influxdata / influxdb-client-dart

InfluxDB (v2+) Client Library for Dart and Flutter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Web - Refused to set unsafe header

catteneo opened this issue · comments

Describe the bug
I'm having an issue when querying an influxdb server on an app running on web.

When I query the server I get this error in Chrome (or Edge) console:

Refused to set unsafe header "Accept-Encoding"
Refused to set unsafe header "User-Agent"

Firefox presents only this one as a warning:

Attempt to set a forbidden header was denied: Accept-Encoding

To Reproduce
Steps to reproduce the behavior:

  1. init client
  2. get query service
  3. query server

Specifications:

  • Client Version: 2.4.0
  • InfluxDB Version: 1.8 or 2.2
  • Platform: Web

Hi @catteneo,

thanks for using our client.

It looks like problem with CORS preflight request where these headers aren't allowed. I will take a look. Thanks for report this.

Regards

Hi @catteneo

When I query the server I get this error in Chrome (or Edge) console:

Refused to set unsafe header "Accept-Encoding"
Refused to set unsafe header "User-Agent"

The User-Agent warning is Chromium issue, see: https://bugs.chromium.org/p/chromium/issues/detail?id=571722. If you would like to remove the User-Agent header from the client requests, you can use something like:

class RemoveUserAgentClient extends http.BaseClient {
  final http.Client _inner = http.Client();

  RemoveUserAgentClient();

  @override
  Future<http.StreamedResponse> send(http.BaseRequest request) {
    request.headers
        .removeWhere((key, value) => key.toLowerCase() == 'user-agent');
    return _inner.send(request);
  }
}
var client = InfluxDBClient(
  url: "https://us-west-2-1.aws.cloud2.influxdata.com",
  token: "my-token",
  org: "my-org",
  client: RemoveUserAgentClient()
)

Firefox presents only this one as a warning:

Attempt to set a forbidden header was denied: Accept-Encoding

After acceptance of #50, you can avoid this by:

var queryService = client.getQueryService(queryOptions: QueryOptions(gzip: false));

Regards