mirror of https://github.com/grpc/grpc-dart.git
Add userAgent for ChannelOptions (#155)
Add userAgent for ChannelOptions
This commit is contained in:
parent
f3e1e32973
commit
c65afe9ec0
|
@ -1,3 +1,8 @@
|
|||
## 1.0.3
|
||||
|
||||
* Add `userAgent` argument for `ChannelOptions()`
|
||||
* Add `userAgent` as an optional named argument for `clientConnection.createCallHeaders()`
|
||||
|
||||
## 1.0.2
|
||||
|
||||
* Fix bug where the server would crash if the client would break the connection.
|
||||
|
|
|
@ -54,7 +54,6 @@ class ClientConnection {
|
|||
static final _teTrailers = new Header.ascii('te', 'trailers');
|
||||
static final _grpcAcceptEncoding =
|
||||
new Header.ascii('grpc-accept-encoding', 'identity');
|
||||
static final _userAgent = new Header.ascii('user-agent', 'dart-grpc/0.2.0');
|
||||
|
||||
final String host;
|
||||
final int port;
|
||||
|
@ -75,7 +74,8 @@ class ClientConnection {
|
|||
ConnectionState get state => _state;
|
||||
|
||||
static List<Header> createCallHeaders(bool useTls, String authority,
|
||||
String path, Duration timeout, Map<String, String> metadata) {
|
||||
String path, Duration timeout, Map<String, String> metadata,
|
||||
{String userAgent}) {
|
||||
final headers = [
|
||||
_methodPost,
|
||||
useTls ? _schemeHttps : _schemeHttp,
|
||||
|
@ -89,7 +89,7 @@ class ClientConnection {
|
|||
_contentTypeGrpc,
|
||||
_teTrailers,
|
||||
_grpcAcceptEncoding,
|
||||
_userAgent,
|
||||
new Header.ascii('user-agent', userAgent ?? defaultUserAgent),
|
||||
]);
|
||||
metadata?.forEach((key, value) {
|
||||
headers.add(new Header(ascii.encode(key), utf8.encode(value)));
|
||||
|
@ -163,7 +163,8 @@ class ClientConnection {
|
|||
ClientTransportStream makeRequest(
|
||||
String path, Duration timeout, Map<String, String> metadata) {
|
||||
final headers = createCallHeaders(
|
||||
options.credentials.isSecure, authority, path, timeout, metadata);
|
||||
options.credentials.isSecure, authority, path, timeout, metadata,
|
||||
userAgent: options.userAgent);
|
||||
return _transport.makeRequest(headers);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import 'dart:math';
|
|||
import '../shared/security.dart';
|
||||
|
||||
const defaultIdleTimeout = const Duration(minutes: 5);
|
||||
const defaultUserAgent = 'dart-grpc/1.0.3';
|
||||
|
||||
typedef Duration BackoffStrategy(Duration lastBackoff);
|
||||
|
||||
|
@ -95,14 +96,16 @@ class ChannelOptions {
|
|||
final ChannelCredentials credentials;
|
||||
final Duration idleTimeout;
|
||||
final BackoffStrategy backoffStrategy;
|
||||
final String userAgent;
|
||||
|
||||
const ChannelOptions(
|
||||
{ChannelCredentials credentials,
|
||||
Duration idleTimeout,
|
||||
BackoffStrategy backoffStrategy =
|
||||
defaultBackoffStrategy}) // Remove when dart-lang/sdk#31066 is fixed.
|
||||
: this.credentials = credentials ?? const ChannelCredentials.secure(),
|
||||
const ChannelOptions({
|
||||
ChannelCredentials credentials,
|
||||
Duration idleTimeout,
|
||||
String userAgent,
|
||||
BackoffStrategy backoffStrategy,
|
||||
}) : this.credentials = credentials ?? const ChannelCredentials.secure(),
|
||||
this.idleTimeout = idleTimeout ?? defaultIdleTimeout,
|
||||
this.userAgent = userAgent ?? defaultUserAgent,
|
||||
this.backoffStrategy = backoffStrategy ?? defaultBackoffStrategy;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: grpc
|
||||
description: Dart implementation of gRPC, a high performance, open-source universal RPC framework.
|
||||
version: 1.0.2
|
||||
version: 1.0.3
|
||||
author: Dart Team <misc@dartlang.org>
|
||||
homepage: https://github.com/dart-lang/grpc-dart
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ Duration testBackoff(Duration lastBackoff) => const Duration(milliseconds: 1);
|
|||
class FakeChannelOptions implements ChannelOptions {
|
||||
ChannelCredentials credentials = const ChannelCredentials.secure();
|
||||
Duration idleTimeout = const Duration(seconds: 1);
|
||||
String userAgent = 'dart-grpc/1.0.0 test';
|
||||
BackoffStrategy backoffStrategy = testBackoff;
|
||||
}
|
||||
|
||||
|
|
|
@ -171,7 +171,8 @@ class ServerHarness {
|
|||
Map<String, String> metadata,
|
||||
Duration timeout}) {
|
||||
final headers = ClientConnection.createCallHeaders(
|
||||
true, authority, path, timeout, metadata);
|
||||
true, authority, path, timeout, metadata,
|
||||
userAgent: 'dart-grpc/1.0.0 test');
|
||||
toServer.add(new HeadersStreamMessage(headers));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue