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