Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1055)

Unified Diff: pkg/appengine/lib/src/protobuf_api/rpc/rpc_service_base.dart

Issue 804973002: Add appengine/gcloud/mustache dependencies. (Closed) Base URL: git@github.com:dart-lang/pub-dartlang-dart.git@master
Patch Set: Added AUTHORS/LICENSE/PATENTS files Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/appengine/lib/src/protobuf_api/rpc/rpc_service_base.dart
diff --git a/pkg/appengine/lib/src/protobuf_api/rpc/rpc_service_base.dart b/pkg/appengine/lib/src/protobuf_api/rpc/rpc_service_base.dart
new file mode 100644
index 0000000000000000000000000000000000000000..02f938ff53eb45c207633d5533a4e041c40dc453
--- /dev/null
+++ b/pkg/appengine/lib/src/protobuf_api/rpc/rpc_service_base.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library rpc_service_base;
+
+import 'dart:async';
+import 'dart:io';
+
+import '../../../api/errors.dart';
+
+abstract class RPCServiceBase {
+ static ContentType RPC_CONTENT_TYPE =
+ new ContentType('application', 'octet-stream');
+
+ HttpClient _client;
+
+ RPCServiceBase() : _client = new HttpClient();
+
+ Future<List<int>> makeRequest(String host,
+ int port,
+ String path,
+ List<int> data,
+ Map<String, String> additionalHeaders) {
+ return _client.post(host, port, path).then((HttpClientRequest request) {
+ var headers = request.headers;
+ headers.contentType = RPC_CONTENT_TYPE;
+ headers.contentLength = data.length;
+
+ for (var key in additionalHeaders.keys) {
+ headers.set(key, additionalHeaders[key]);
+ }
+
+ request.add(data);
+ return request.close().then((HttpClientResponse response) {
+ if (response.statusCode != HttpStatus.OK) {
+ return response.drain().then((_) {
+ throw new ProtocolError("Http statusCode was "
+ "${response.statusCode} instead of ${HttpStatus.OK}");
+ });
+ }
+ return response.fold(new BytesBuilder(), (buffer, data) {
+ buffer.add(data);
+ return buffer;
+ }).then((BytesBuilder buffer) => buffer.takeBytes());
+ });
+ }).catchError((error) {
+ throw new NetworkError('$error $port $host');
+ });
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698