Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

add support for user added headers in http requests #26

Merged
merged 4 commits into from
Aug 17, 2021

Conversation

unsuitable001
Copy link
Contributor

This PR adds support for HttpHeaders.set method only for setting arbitrary http headers.

Closes #25


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);
Copy link
Contributor

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.

Copy link
Contributor Author

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 initiated HttpClientRequest 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. 😀

lib/src/http_client_request.dart Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
lib/src/http_client_request.dart Outdated Show resolved Hide resolved
///
/// In some situations, headers are immutable:
/// * [HttpClientRequest] have immutable headers from the moment the body is
/// written to.
Copy link
Member

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.

Copy link
Contributor Author

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.

lib/src/http_headers.dart Show resolved Hide resolved
@dcharkes dcharkes merged commit 3870b22 into google:main Aug 17, 2021
@unsuitable001 unsuitable001 deleted the header_support branch August 17, 2021 15:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding user specified headers in http request
3 participants