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

Refused to set unsafe header "User-Agent" #112

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.1.3
### Fixed User-Agent headers for Web

- [Bug] Check if we are running as a web app before setting User-Agent headers.

## 1.1.2
### Add custom params to requests

Expand Down
6 changes: 3 additions & 3 deletions lib/algolia.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'dart:async';
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:uuid/uuid.dart';
import 'package:universal_io/io.dart' show Platform;
import 'package:uuid/uuid.dart';

part 'src/algolia.dart';
part 'src/batch.dart';
Expand All @@ -17,9 +17,9 @@ part 'src/index_settings.dart';
part 'src/index_snapshot.dart';
part 'src/object_reference.dart';
part 'src/object_snapshot.dart';
part 'src/synonyms_reference.dart';
part 'src/query.dart';
part 'src/query_snapshot.dart';
part 'src/synonyms_reference.dart';
part 'src/task.dart';
part 'src/util/json_encode.dart';
part 'src/util/enum_util.dart';
part 'src/util/json_encode.dart';
5 changes: 4 additions & 1 deletion lib/src/algolia.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class Algolia {
String get _hostFallback3 => 'https://$applicationId-3.algolianet.com/1/';
String get _insightsHost => 'https://insights.algolia.io/1/';

final _isWeb = const bool.fromEnvironment(
'dart.library.js_util'); // this will return true if compiled to web

List<String> get _userAgents {
final os = "${Platform.operatingSystem} ${Platform.operatingSystemVersion}";
final dart = "Dart ${Platform.version}";
Expand All @@ -68,7 +71,7 @@ class Algolia {
'X-Algolia-Application-Id': applicationId,
'X-Algolia-API-Key': _apiKey,
'Content-Type': 'application/json',
'User-Agent': _userAgents.join(";"),
if (!_isWeb) 'User-Agent': _userAgents.join(";"),
};
map.addEntries(extraHeaders.entries);
return map;
Expand Down
Loading