Skip to content

Commit 0985a1c

Browse files
authored
fix(clients): use correct user agent (#4103)
1 parent 66acf19 commit 0985a1c

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

clients/algoliasearch-client-dart/packages/client_core/lib/src/transport/dio/platform/platform_web.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ Iterable<AgentSegment> platformAgentSegments() => [
1313

1414
/// [AlgoliaAgent] for web platforms as query param.
1515
void platformAlgoliaAgent(dio.RequestOptions options, String agent) {
16-
options.queryParameters["X-Algolia-Agent"] = agent;
16+
options.queryParameters["x-algolia-agent"] = agent;
1717
}

clients/algoliasearch-client-swift/Sources/Core/Networking/RequestBuilder/EchoRequestBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ final class EchoRequestBuilder: RequestBuilder {
7878
originalBodyData: urlRequest.httpBody,
7979
path: urlComponents?.percentEncodedPath ?? "",
8080
host: url.host ?? "",
81-
algoliaAgent: headers["X-Algolia-Agent"] ?? "",
81+
algoliaAgent: headers["User-Agent"] ?? "",
8282
queryParameters: queryParameters,
8383
headers: headers
8484
)

templates/swift/tests/client/tests.mustache

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,8 @@
2929
{{/shouldScope}}
3030
{{#dynamicTemplate}}{{/dynamicTemplate}}
3131
{{#testUserAgent}}
32-
let userAgent = try XCTUnwrap(echoResponse.headers?["User-Agent"])
33-
guard let userAgent = userAgent else {
34-
XCTFail("Expected user-agent header")
35-
return
36-
}
37-
3832
let pattern = "{{#lambda.escapeSlash}}{{{match.value}}}{{/lambda.escapeSlash}}"
39-
XCTAssertNoThrow(try regexMatch(userAgent, against: pattern), "Expected " + userAgent + " to match the following regex: " + pattern);
33+
XCTAssertNoThrow(try regexMatch(echoResponse.algoliaAgent, against: pattern), "Expected " + echoResponse.algoliaAgent + " to match the following regex: " + pattern);
4034
{{/testUserAgent}}
4135
{{#testTimeouts}}
4236
XCTAssertEqual(TimeInterval({{{matchResponseTimeout}}} / 1000), echoResponse.timeout);

tests/output/swift/Tests/Utils/Utils.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public func union(expected: Any?, received: Any?) -> Any? {
9797
}
9898

9999
public func regexMatch(_ received: String, against: String) -> Bool {
100-
let matches = try! NSRegularExpression(pattern: against).matches(in: received, range: .init(location: 0, length: received.utf16.count))
100+
let matches = try! NSRegularExpression(pattern: against).matches(
101+
in: received,
102+
range: .init(location: 0, length: received.utf16.count)
103+
)
101104
return !matches.isEmpty
102105
}

website/docs/add-new-language.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ The `User-Agent` MUST match the following regular expression:
110110
^Algolia for <LANGUAGE> \\(\\d+\\.\\d+\\.\\d+(-?.*)?\\)(; [a-zA-Z. ]+ (\\(\\d+((\\.\\d+)?\\.\\d+)?(-?.*)?\\))?)*(; <CLIENT> (\\(\\d+\\.\\d+\\.\\d+(-?.*)?\\)))(; [a-zA-Z. ]+ (\\(\\d+((\\.\\d+)?\\.\\d+)?(-?.*)?\\))?)*$
111111
```
112112

113-
The function MUST be named `addAlgoliaAgent` because of JavaScript exception that doesn't allow custom `User-Agent` in the header, and must use `x-algolia-agent` for JavaScript.
113+
The function MUST be named `addAlgoliaAgent` because of JavaScript exception that doesn't allow custom `User-Agent` in the header, and must use `x-algolia-agent` for JavaScript and Dart.
114114

115115
### Dependencies
116116

0 commit comments

Comments
 (0)