Request constructor
Creates a new Request.
handlerPath
must be root-relative. url
's path must be fully relative,
and it must have the same query parameters as requestedUri
.
handlerPath
and url
's path must combine to be the path component of
requestedUri
. If they're not passed, handlerPath
will default to /
and url
to requestedUri.path
without the initial /
. If only one is
passed, the other will be inferred.
body
is the request body. It may be either a String, a List<int>, a
Stream<List<int>>, or null
to indicate no body. If it's a String,
encoding
is used to encode it to a Stream<List<int>>. The default
encoding is UTF-8.
If encoding
is passed, the "encoding" field of the Content-Type header
in headers
will be set appropriately. If there is no existing
Content-Type header, it will be set to "application/octet-stream".
headers
must contain values that are either String
or List<String>
.
An empty list will cause the header to be omitted.
The default value for protocolVersion
is '1.1'.
onHijack
onHijack
allows handlers to take control of the underlying socket for
the request. It should be passed by adapters that can provide access to
the bidirectional socket underlying the HTTP connection stream.
The onHijack
callback will only be called once per request. It will be
passed another callback which takes a byte StreamChannel. onHijack
must
pass the channel for the connection stream to this callback, although it
may do so asynchronously.
If a request is hijacked, the adapter should expect to receive a
HijackException
from the handler. This is a special exception used to
indicate that hijacking has occurred. The adapter should avoid either
sending a response or notifying the user of an error if a
HijackException
is caught.
An adapter can check whether a request was hijacked using canHijack,
which will be false
for a hijacked request. The adapter may throw an
error if a HijackException
is received for a non-hijacked request, or if
no HijackException
is received for a hijacked request.
See also hijack.
Implementation
// TODO(kevmoo) finish documenting the rest of the arguments.
Request(
String method,
Uri requestedUri, {
String? protocolVersion,
Map<String, /* String | List<String> */ Object>? headers,
String? handlerPath,
Uri? url,
Object? body,
Encoding? encoding,
Map<String, Object>? context,
void Function(void Function(StreamChannel<List<int>>))? onHijack,
}) : this._(method, requestedUri,
protocolVersion: protocolVersion,
headers: headers,
url: url,
handlerPath: handlerPath,
body: body,
encoding: encoding,
context: context,
onHijack: onHijack == null ? null : _OnHijack(onHijack));