Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP-6213 Static methods on Http class do not allow content-type header to be explicitly set #302

Open
evanweible-wf opened this issue Mar 9, 2018 · 0 comments

Comments

@evanweible-wf
Copy link
Contributor

evanweible-wf commented Mar 9, 2018

Because the static request methods on the Http class are implemented by creating a Request instance and setting the uri and headers fields, there is an issue where the content-type header cannot be defined because the Request class is assumed to be of content-type text/plain. In other words, the following does not work as one would expect:

final uri = ...;
Http.post(uri, headers: {'content-type': 'application/json'});
// Should send a request with content-type: application/json
// but actually sends a request with content-type: text/plain

The workaround is to construct the appropriate request class instance and modify the content-type via the contentType field:

// Some content-types like application/json are handled by classes
// provided by w_transport:
final jsonRequest = new JsonRequest();
jsonRequest.post(); // will be sent with content-type: application/json

// If there isn't a class that supports your desired content-type,
// you can construct a regular `Request` and set it manually:
final xmlRequest = new Request()
  ..contentType = new MediaType('application', 'xml');
xmlRequest.post(); // will be sent with content-type: application/xml
@rmconsole-wf rmconsole-wf changed the title Static methods on Http class do not allow content-type header to be explicitly set WP-6213 Static methods on Http class do not allow content-type header to be explicitly set Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant