Format and update .gitginore (#4)
diff --git a/.gitignore b/.gitignore
index 65593da..f43eb62 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
-packages
pubspec.lock
.packages
+.pub/
diff --git a/example/example_server.dart b/example/example_server.dart
index f8dd2cf..edca6e5 100644
--- a/example/example_server.dart
+++ b/example/example_server.dart
@@ -18,8 +18,8 @@
var apiHandler = (Request request) {
if (request.url.path == '/api') {
apiCount++;
- var json = _encoder.convert({ 'count': apiCount});
- var headers = { 'Content-Type' : 'application/json' };
+ var json = _encoder.convert({'count': apiCount});
+ var headers = {'Content-Type': 'application/json'};
return new Response.ok(json, headers: headers);
}
@@ -38,8 +38,8 @@
// Creates a pipeline handler which first logs requests and then sends them
// to the cascade.
//
- var handler = const Pipeline().addMiddleware(logRequests())
- .addHandler(cascade.handler);
+ var handler =
+ const Pipeline().addMiddleware(logRequests()).addHandler(cascade.handler);
//
// Serve the combined handler on localhost at port 8080.
diff --git a/lib/shelf_proxy.dart b/lib/shelf_proxy.dart
index 47bfbcf..a045b7d 100644
--- a/lib/shelf_proxy.dart
+++ b/lib/shelf_proxy.dart
@@ -31,8 +31,8 @@
// TODO(nweiz): Handle TRACE requests correctly. See
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.8
var requestUrl = url.resolve(serverRequest.url.toString());
- var clientRequest = new http.StreamedRequest(
- serverRequest.method, requestUrl);
+ var clientRequest =
+ new http.StreamedRequest(serverRequest.method, requestUrl);
clientRequest.followRedirects = false;
clientRequest.headers.addAll(serverRequest.headers);
clientRequest.headers['Host'] = url.authority;
@@ -60,16 +60,16 @@
// Add a Warning header. See
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.2
- _addHeader(clientResponse.headers, 'warning',
- '214 $proxyName "GZIP decoded"');
+ _addHeader(
+ clientResponse.headers, 'warning', '214 $proxyName "GZIP decoded"');
}
// Make sure the Location header is pointing to the proxy server rather
// than the destination server, if possible.
if (clientResponse.isRedirect &&
clientResponse.headers.containsKey('location')) {
- var location = requestUrl.resolve(clientResponse.headers['location'])
- .toString();
+ var location =
+ requestUrl.resolve(clientResponse.headers['location']).toString();
if (p.url.isWithin(url.toString(), location)) {
clientResponse.headers['location'] =
'/' + p.url.relative(location, from: url.toString());
@@ -79,8 +79,7 @@
}
return new Response(clientResponse.statusCode,
- body: clientResponse.stream,
- headers: clientResponse.headers);
+ body: clientResponse.stream, headers: clientResponse.headers);
});
};
}
diff --git a/pubspec.yaml b/pubspec.yaml
index 977f73d..bca7772 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: shelf_proxy
-version: 0.1.0+4
+version: 0.1.1-dev
author: Dart Team <misc@dartlang.org>
description: A shelf handler for proxying requests to another server.
homepage: https://github.com/dart-lang/shelf_proxy
diff --git a/test/shelf_proxy_test.dart b/test/shelf_proxy_test.dart
index b88f059..7524205 100644
--- a/test/shelf_proxy_test.dart
+++ b/test/shelf_proxy_test.dart
@@ -35,10 +35,7 @@
return new shelf.Response.ok(':)');
});
- get(headers: {
- 'foo': 'bar',
- 'accept': '*/*'
- });
+ get(headers: {'foo': 'bar', 'accept': '*/*'});
});
test("forwards request body", () {
@@ -55,23 +52,25 @@
return new shelf.Response(567);
});
- expect(get().then((response) {
- expect(response.statusCode, equals(567));
- }), completes);
+ expect(
+ get().then((response) {
+ expect(response.statusCode, equals(567));
+ }),
+ completes);
});
test("forwards response headers", () {
createProxy((request) {
- return new shelf.Response.ok(':)', headers: {
- 'foo': 'bar',
- 'accept': '*/*'
- });
+ return new shelf.Response.ok(':)',
+ headers: {'foo': 'bar', 'accept': '*/*'});
});
- expect(get().then((response) {
- expect(response.headers, containsPair('foo', 'bar'));
- expect(response.headers, containsPair('accept', '*/*'));
- }), completes);
+ expect(
+ get().then((response) {
+ expect(response.headers, containsPair('foo', 'bar'));
+ expect(response.headers, containsPair('accept', '*/*'));
+ }),
+ completes);
});
test("forwards response body", () {
@@ -116,9 +115,11 @@
test("adds a Via header to the response", () {
createProxy((request) => new shelf.Response.ok(':)'));
- expect(get().then((response) {
- expect(response.headers, containsPair('via', '1.1 shelf_proxy'));
- }), completes);
+ expect(
+ get().then((response) {
+ expect(response.headers, containsPair('via', '1.1 shelf_proxy'));
+ }),
+ completes);
});
test("adds to a response's existing Via header", () {
@@ -126,10 +127,12 @@
return new shelf.Response.ok(':)', headers: {'via': '1.0 something'});
});
- expect(get().then((response) {
- expect(response.headers,
- containsPair('via', '1.0 something, 1.1 shelf_proxy'));
- }), completes);
+ expect(
+ get().then((response) {
+ expect(response.headers,
+ containsPair('via', '1.0 something, 1.1 shelf_proxy'));
+ }),
+ completes);
});
test("adds to a response's existing Via header", () {
@@ -137,10 +140,12 @@
return new shelf.Response.ok(':)', headers: {'via': '1.0 something'});
});
- expect(get().then((response) {
- expect(response.headers,
- containsPair('via', '1.0 something, 1.1 shelf_proxy'));
- }), completes);
+ expect(
+ get().then((response) {
+ expect(response.headers,
+ containsPair('via', '1.0 something, 1.1 shelf_proxy'));
+ }),
+ completes);
});
});
@@ -150,10 +155,12 @@
return new shelf.Response.found('http://dartlang.org');
});
- expect(get().then((response) {
- expect(response.headers,
- containsPair('location', 'http://dartlang.org'));
- }), completes);
+ expect(
+ get().then((response) {
+ expect(response.headers,
+ containsPair('location', 'http://dartlang.org'));
+ }),
+ completes);
});
test("relativizes a reachable root-relative Location", () {
@@ -161,9 +168,11 @@
return new shelf.Response.found('/foo/bar');
}, targetPath: '/foo');
- expect(get().then((response) {
- expect(response.headers, containsPair('location', '/bar'));
- }), completes);
+ expect(
+ get().then((response) {
+ expect(response.headers, containsPair('location', '/bar'));
+ }),
+ completes);
});
test("absolutizes an unreachable root-relative Location", () {
@@ -171,42 +180,45 @@
return new shelf.Response.found('/baz');
}, targetPath: '/foo');
- expect(get().then((response) {
- expect(response.headers,
- containsPair('location', targetUri.resolve('/baz').toString()));
- }), completes);
+ expect(
+ get().then((response) {
+ expect(response.headers,
+ containsPair('location', targetUri.resolve('/baz').toString()));
+ }),
+ completes);
});
});
test("removes a transfer-encoding header", () {
var handler = mockHandler((request) {
- return new http.Response('', 200, headers: {
- 'transfer-encoding': 'chunked'
- });
+ return new http.Response('', 200,
+ headers: {'transfer-encoding': 'chunked'});
});
- expect(handler(new shelf.Request('GET', Uri.parse('http://localhost/')))
- .then((response) {
- expect(response.headers, isNot(contains("transfer-encoding")));
- }), completes);
+ expect(
+ handler(new shelf.Request('GET', Uri.parse('http://localhost/')))
+ .then((response) {
+ expect(response.headers, isNot(contains("transfer-encoding")));
+ }),
+ completes);
});
test("removes content-length and content-encoding for a gzipped response",
() {
var handler = mockHandler((request) {
- return new http.Response('', 200, headers: {
- 'content-encoding': 'gzip',
- 'content-length': '1234'
- });
+ return new http.Response('', 200,
+ headers: {'content-encoding': 'gzip', 'content-length': '1234'});
});
- expect(handler(new shelf.Request('GET', Uri.parse('http://localhost/')))
- .then((response) {
- expect(response.headers, isNot(contains("content-encoding")));
- expect(response.headers, isNot(contains("content-length")));
- expect(response.headers,
- containsPair('warning', '214 shelf_proxy "GZIP decoded"'));
- }), completes);
+ expect(
+ handler(new shelf.Request('GET', Uri.parse('http://localhost/')))
+ .then((response) {
+ expect(response.headers, isNot(contains("content-encoding")));
+ expect(response.headers, isNot(contains("content-length")));
+ expect(response.headers,
+ containsPair('warning', '214 shelf_proxy "GZIP decoded"'));
+ }),
+ completes);
});
}
@@ -220,10 +232,11 @@
return shelf_io.serve(handler, 'localhost', 0).then((targetServer) {
targetUri = Uri.parse('http://localhost:${targetServer.port}');
if (targetPath != null) targetUri = targetUri.resolve(targetPath);
- var proxyServerHandler = expectAsync(
- proxyHandler(targetUri), reason: 'proxy server handler');
+ var proxyServerHandler =
+ expectAsync(proxyHandler(targetUri), reason: 'proxy server handler');
- return shelf_io.serve(proxyServerHandler, 'localhost', 0)
+ return shelf_io
+ .serve(proxyServerHandler, 'localhost', 0)
.then((proxyServer) {
proxyUri = Uri.parse('http://localhost:${proxyServer.port}');