Skip to content
Open
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
10 changes: 10 additions & 0 deletions pkgs/ok_http/lib/src/ok_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class OkHttpClientConfiguration {
/// This should only be used in a testing environment.
final bool validateServerCertificates;

final String? userAgent;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add dart doc for this?


const OkHttpClientConfiguration({
this.callTimeout = Duration.zero,
this.connectTimeout = const Duration(milliseconds: 10000),
Expand All @@ -99,6 +101,7 @@ class OkHttpClientConfiguration {
this.clientPrivateKey,
this.clientCertificateChain,
this.validateServerCertificates = true,
this.userAgent,
});
}

Expand Down Expand Up @@ -358,6 +361,13 @@ class OkHttpClient extends BaseClient {
reqBuilder.addHeader(headerName.toJString(), headerValue.toJString());
});

if (configuration.userAgent != null) {
reqBuilder.addHeader(
JString.fromString('User-Agent'),
JString.fromString(configuration.userAgent!),
);
}

// OkHttp doesn't allow a non-null RequestBody for GET and HEAD requests.
// So, we need to handle this case separately.
bindings.RequestBody? okReqBody;
Expand Down
Loading