From 17ce11f7fcce510cf8cccd8e31026c6f8eb1e061 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Thu, 19 Jul 2018 15:46:23 +0200 Subject: [PATCH] Allow for non ascii headers (#103) --- CHANGELOG.md | 4 ++++ lib/src/client/connection.dart | 7 ++++--- lib/src/server/handler.dart | 9 +++++---- lib/src/shared/streams.dart | 2 +- pubspec.yaml | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c840228..50cb745 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.2 - 2018-07-19 + +* Allow for non-ascii header values. + ## 0.6.1 - 2018-07-13 * More fixes to update to Dart 2 core library APIs. diff --git a/lib/src/client/connection.dart b/lib/src/client/connection.dart index 770abaa..46f2f5f 100644 --- a/lib/src/client/connection.dart +++ b/lib/src/client/connection.dart @@ -14,6 +14,7 @@ // limitations under the License. import 'dart:async'; +import 'dart:convert'; import 'dart:io'; import 'package:http2/transport.dart'; @@ -78,8 +79,8 @@ class ClientConnection { final headers = [ _methodPost, useTls ? _schemeHttps : _schemeHttp, - new Header.ascii(':path', path), - new Header.ascii(':authority', authority), + new Header(ascii.encode(':path'), utf8.encode(path)), + new Header(ascii.encode(':authority'), utf8.encode(authority)), ]; if (timeout != null) { headers.add(new Header.ascii('grpc-timeout', toTimeoutString(timeout))); @@ -91,7 +92,7 @@ class ClientConnection { _userAgent, ]); metadata?.forEach((key, value) { - headers.add(new Header.ascii(key, value)); + headers.add(new Header(ascii.encode(key), utf8.encode(value))); }); return headers; } diff --git a/lib/src/server/handler.dart b/lib/src/server/handler.dart index 4a41155..2354416 100644 --- a/lib/src/server/handler.dart +++ b/lib/src/server/handler.dart @@ -14,6 +14,7 @@ // limitations under the License. import 'dart:async'; +import 'dart:convert'; import 'package:http2/transport.dart'; @@ -268,8 +269,8 @@ class ServerHandler extends ServiceCall { _customHeaders = null; final outgoingHeaders =
[]; - outgoingHeadersMap.forEach( - (key, value) => outgoingHeaders.add(new Header.ascii(key, value))); + outgoingHeadersMap.forEach((key, value) => + outgoingHeaders.add(new Header(ascii.encode(key), utf8.encode(value)))); _stream.sendHeaders(outgoingHeaders); _headersSent = true; } @@ -296,8 +297,8 @@ class ServerHandler extends ServiceCall { } final outgoingTrailers =
[]; - outgoingTrailersMap.forEach( - (key, value) => outgoingTrailers.add(new Header.ascii(key, value))); + outgoingTrailersMap.forEach((key, value) => + outgoingTrailers.add(new Header(ascii.encode(key), utf8.encode(value)))); _stream.sendHeaders(outgoingTrailers, endStream: true); // We're done! _cancelResponseSubscription(); diff --git a/lib/src/shared/streams.dart b/lib/src/shared/streams.dart index 60fb620..7e3148b 100644 --- a/lib/src/shared/streams.dart +++ b/lib/src/shared/streams.dart @@ -60,7 +60,7 @@ class GrpcHttpEncoder extends Converter { if (input is GrpcMetadata) { final headers =
[]; input.metadata.forEach((key, value) { - headers.add(new Header.ascii(key, value)); + headers.add(new Header(ascii.encode(key), utf8.encode(value))); }); return new HeadersStreamMessage(headers); } else if (input is GrpcData) { diff --git a/pubspec.yaml b/pubspec.yaml index bd766fb..98838af 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: grpc description: Dart implementation of gRPC. -version: 0.6.1 +version: 0.6.2 author: Dart Team homepage: https://github.com/dart-lang/grpc-dart