only allow GET method to be proxied
diff --git a/lib/shelf_proxy.dart b/lib/shelf_proxy.dart
index 28a806d..04baf41 100644
--- a/lib/shelf_proxy.dart
+++ b/lib/shelf_proxy.dart
@@ -24,6 +24,10 @@
}
return (Request request) {
+ if (request.method != 'GET') {
+ return new Response(HttpStatus.METHOD_NOT_ALLOWED);
+ }
+
// TODO: really need to tear down the client when this is done...
var client = new HttpClient();
diff --git a/test/proxy_test.dart b/test/proxy_test.dart
index 4a6b3eb..85be0b9 100644
--- a/test/proxy_test.dart
+++ b/test/proxy_test.dart
@@ -78,7 +78,7 @@
});
});
- test('bar', () {
+ test('/bar', () {
_scheduleServer(_handler);
schedule(() {
@@ -92,7 +92,7 @@
});
});
- test('bar/', () {
+ test('/bar/', () {
_scheduleServer(_handler);
schedule(() {
@@ -105,6 +105,19 @@
});
});
});
+
+ test('only GET is supported', () {
+ _scheduleServer(_handler);
+
+ schedule(() {
+ var url = new Uri.http('localhost:$_serverPort', '');
+ var handler = createProxyHandler(url);
+
+ return makeRequest(handler, '/', method: 'PUT').then((response) {
+ expect(response.statusCode, HttpStatus.METHOD_NOT_ALLOWED);
+ });
+ });
+ });
});
}
diff --git a/test/test_util.dart b/test/test_util.dart
index eedd672..b4275dc 100644
--- a/test/test_util.dart
+++ b/test/test_util.dart
@@ -14,13 +14,17 @@
/// Makes a simple GET request to [handler] and returns the result.
Future<Response> makeRequest(Handler handler, String path,
- {String scriptName, Map<String, String> headers}) {
+ {String scriptName, Map<String, String> headers, String method}) {
var rootedHandler = _rootHandler(scriptName, handler);
- return syncFuture(() => rootedHandler(_fromPath(path, headers)));
+ return syncFuture(() =>
+ rootedHandler(_fromPath(path, headers, method: method)));
}
-Request _fromPath(String path, Map<String, String> headers) =>
- new Request('GET', Uri.parse('http://localhost' + path), headers: headers);
+Request _fromPath(String path, Map<String, String> headers, {String method}) {
+ if (method == null) method = 'GET';
+ return new Request(method, Uri.parse('http://localhost' + path),
+ headers: headers);
+}
Handler _rootHandler(String scriptName, Handler handler) {
if (scriptName == null || scriptName.isEmpty) {