Proxy class

Proxy for handling requests to another server.

This is an experimental implementation. It is not complete, so it might not work in all situations.

Create Proxy objects for the requests and then register request handlers with the server's pipelines.

Example:

final server = ...

final pipeline = ...

final proxy = Proxy('~/foobar/*', 'http://example.com');

// Register the proxy as the handler for the requests

pipeline.get(proxy.pattern, proxy.handler);

// Register all HTTP methods to proxy:

pipeline.head(proxy.pattern, proxy.handler);
pipeline.post(proxy.pattern, proxy.handler);

// The above syntax is equivalent to passing in a function that invokes the
// `handler` method on the _proxy_ object. That is,
//     pipeline.put(p.pattern, (r) => p.handler(r));

await server.run();

GET/HEAD/POST requests for '~/foobar/abc/def' will return the response from sending a request to "http://example.com/abc/def".

The Proxy object constructor takes the pattern for the requests the proxy will handle, and the URL that the requests will be sent to.

When registering request handlers, the proxy.pattern getter should be used to ensure consistency. If the registered pattern does not match the pattern used to create the object, it might not work properly. Also, in the above example, proxy.handler is a tear-off which is equivalent to invoking the handler method on the proxy object. That is, p.handler is the same as creating a new function (r) { return p.handler(r); } that invokes the method on the object.

Debugging client side Dart scripts

This was developed to proxy requests for the Web assets (e.g. images, CSS and client side scripts) to a running "webdev serve" instance, so client side Dart can be debugged in conjunction with a Web server running server side Dart. Currently, this seems to work when webdev serve is run with --no-injected-client. But it does not work with "webdev daemon" (which is what WebStorm uses to debug client side Dart). So you can set Dart breakpoints in Chrome, but not in WebStorm.

Constructors

Proxy(String pattern, String proxy, {String receivedBy = _receivedByDefault, bool includeViaHeaderInResponse = true})
Create a request handler that proxies requests to another URL.

Properties

hashCode int
The hash code for this object.
no setterinherited
includeViaHeaderInResponse bool
Indicates if a Via header is added to the response.
final
pattern String
The pattern handled for this proxy.
no setter
postMaxRequestSize int
Maximum size of POST contents before it is rejected.
getter/setter pair
requestBlockHeaders List<String>
Additional request headers which are not passed through to the target.
final
responseBlockHeaders List<String>
Additional response headers which are not passed through to the client.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

handler(Request req) Future<Response>
Request handler.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

requestHeadersNeverPass → const List<String>
Headers in the request which are never passed through to the target.
responseHeadersNeverPass → const List<String>
Headers in the response which are never passed through to the client.