|
Motion Master 6.0.0-alpha.86
Next-generation motion control software
|
A request, snapshotted on the loop thread so a handler can outlive it. More...
#include <router.h>
Public Member Functions | |
| Request (std::string url, std::vector< std::pair< std::string, std::string > > parameters, std::string queryString, std::vector< std::pair< std::string, std::string > > headers, std::string body) | |
| std::string_view | url () const |
| The full request path. | |
| const std::string & | body () const |
| The request body, empty for methods that carry none. Complete — a handler never sees a partial body, because dispatch waits for the last chunk. | |
| std::string_view | header (std::string_view name) const |
| A request header by name, lower-cased as uWS delivers it, or empty when absent. | |
| bool | accepts (std::string_view contentType) const |
Whether Accept asks for contentType. Substring, matching how these endpoints have always negotiated: an Accept of *‍/* or absent means "the default", not "any". | |
| std::string_view | parameter (std::string_view name) const |
A path parameter by the name the route pattern declared (:slavePosition), or empty. | |
| std::optional< std::string > | query (std::string_view key) const |
A query-string value by key, percent-decoded, or std::nullopt when it has no value. | |
| template<typename T > | |
| std::optional< T > | parameterAs (std::string_view name) const |
A path parameter parsed as an integer, or std::nullopt if it is absent or not one. | |
| template<typename T > | |
| std::optional< T > | queryAs (std::string_view key) const |
A query value parsed as an integer, or std::nullopt if absent or not one. | |
A request, snapshotted on the loop thread so a handler can outlive it.
uWS's own HttpRequest is valid only during the synchronous handler call; everything a handler might read is therefore copied out before any work is dispatched. That is a few string copies per request, against a handler that is about to do milliseconds of wire I/O.
|
inline |
|
inline |
Whether Accept asks for contentType. Substring, matching how these endpoints have always negotiated: an Accept of *‍/* or absent means "the default", not "any".
|
inline |
The request body, empty for methods that carry none. Complete — a handler never sees a partial body, because dispatch waits for the last chunk.
|
inline |
A request header by name, lower-cased as uWS delivers it, or empty when absent.
Needed for content negotiation: several endpoints return raw bytes or parsed JSON depending on Accept, and one reads Content-Type.
|
inline |
A path parameter by the name the route pattern declared (:slavePosition), or empty.
Verbatim — still percent-encoded. uWS decodes query values but not path segments, and neither does this. Harmless for every parameter the API has today, all of which are numbers or fixed slugs that no client would encode. A route taking free-form text in its path is the case to watch: pass it through percentDecode, as the user-cache routes do, or a name containing a space arrives as %20 and names nothing.
|
inline |
A path parameter parsed as an integer, or std::nullopt if it is absent or not one.
Accepts a 0x prefix, because a CoE index is written that way everywhere else — its documentation, the Console, the specification — and a route that only took decimal would make a user convert by hand. Trailing characters are rejected, so 12abc is not 12.
| std::optional< std::string > mm::api::Request::query | ( | std::string_view | key | ) | const |
A query-string value by key, percent-decoded, or std::nullopt when it has no value.
Delegates to uWebSockets' own uWS::getDecodedQueryValue — the same function HttpRequest::getQuery(key) uses — so a handler reading a query here gets exactly what it would have got reading it on the loop thread. Decoding is the reason this is not a hand-rolled split: a client encodes its query values (the generated TypeScript client runs every one through encodeURIComponent), so positions=1,2 arrives as positions=1%2C2 and a raw split yields 1%2C2 — which parses as no number at all.
Follows uWS's semantics rather than inventing any: a key needs an = to be seen at all, and a present-but-empty value is reported the same as an absent one. So ?flag alone is not a usable flag — test a value, not presence.
Returns an owned string because the decode happens in place: each call decodes into its own copy of the query, which is what keeps repeated lookups independent of each other.
|
inline |
A query value parsed as an integer, or std::nullopt if absent or not one.
|
inline |
The full request path.