-
Notifications
You must be signed in to change notification settings - Fork 16
add support for user added headers in http requests #26
Conversation
|
||
test('Send an arbitrary http header to the server', () async { | ||
final request = await client.getUrl(Uri.parse('http://$host:$port/')); | ||
request.headers.set('test-header', sentData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also provide users a way to set multiple headers? What do you think?
I think a very popular use case would be to have a standard set of headers which is used in multiple requests to an API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will be handy indeed :).
We can plan to introduce 2 new apis in a later pr:
headers.setAll
that will take a map of header name and value.- An API to set headers to
HttpClient
that all the initiatedHttpClientRequest
will use by default.
These 2 APIs aren't part of dart:io
as of now. But, will be a really nice addition to this package.
Easy way of adding few common headers will be added via #27 to comply with dart:io
apis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. 😀
lib/src/http_headers.dart
Outdated
/// | ||
/// In some situations, headers are immutable: | ||
/// * [HttpClientRequest] have immutable headers from the moment the body is | ||
/// written to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the rest of the documentation from https://api.dart.dev/stable/2.13.4/dart-io/HttpHeaders-class.html as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some more. Can't add all of it as in this PR, not all of the HttpHeaders apis are implemented.
This PR adds support for
HttpHeaders.set
method only for setting arbitrary http headers.Closes #25