Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Sets unsafe headers #170

Open
bergwerf opened this issue Mar 27, 2017 · 4 comments
Open

Sets unsafe headers #170

bergwerf opened this issue Mar 27, 2017 · 4 comments

Comments

@bergwerf
Copy link

I use this library to generate client code for my own API that I wrote using rpc. The generated code tries to set Content-Length and User-Agent on the requests. However these headers are considered unsafe by the browser. I think it would be appropriate to at least have an option to not set these headers.

@mkustermann
Copy link
Contributor

The generator emits code which is used on web and non-web applications, so generally speaking setting the content-length and user-agent headers is understandable.

Generated Api classes accept an http.Client: The workaround at the moment is to make a wrapper of http.Client which removes the two headers and sends the request to the underlying http.Client.

@bergwerf
Copy link
Author

Right. So you suggest overriding BrowserClient.send and removing both headers from the header map before calling the super method?

@bergwerf
Copy link
Author

bergwerf commented Mar 29, 2017

For future reference, I now use this code which works without issues for my use cases.

class ApiBrowserClient extends BrowserClient {
  @override
  Future<StreamedResponse> send(request) {
    request.headers..remove('content-length')..remove('user-agent');
    return super.send(request);
  }
}

@jakuub
Copy link

jakuub commented Mar 29, 2017

We are using almost the same code for approximetly one year, and everything works fine for us too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants