Dart API Referencedart:ioHttpClientConnection

HttpClientConnection Interface

A HttpClientConnection is returned by all HttpClient methods that initiate a connection to an HTTP server. The handlers will be called as the connection state progresses.

The setting of all handlers is optional. If onRequest is not set the request will be send without any additional headers and an empty body. If onResponse is not set the response will be read and discarded.

Methods

Code HttpConnectionInfo get connectionInfo() #

Get information about the client connection. Returns null if the socket isn't available.

HttpConnectionInfo get connectionInfo();

Code DetachedSocket detachSocket() #

Detach the underlying socket from the HTTP client. When the socket is detached the HTTP client will no longer perform any operations on it.

This is normally used when a HTTP upgrade is negotiated and the communication should continue with a different protocol.

DetachedSocket detachSocket();

Code void set onError(void callback(e)) #

Sets the handler that gets called if an error occurs while connecting or processing the HTTP request.

void set onError(void callback(e));

Code void set onRequest(void callback(HttpClientRequest request)) #

Sets the handler that is called when the connection is established.

void set onRequest(void callback(HttpClientRequest request));

Code void set onResponse(void callback(HttpClientResponse response)) #

Sets callback to be called when the request has been send and the response is ready for processing. The callback is called when all headers of the response are received and data is ready to be received.

void set onResponse(void callback(HttpClientResponse response));

Code void redirect([String method, Uri url]) #

Redirect this connection to a new URL. The default value for method is the method for the current request. The default value for url is the value of the HttpStatus.LOCATION header of the current response. All body data must have been read from the current response before calling redirect.

void redirect([String method, Uri url]);

Code List<RedirectInfo> get redirects() #

Returns the series of redirects this connection has been through.

List<RedirectInfo> get redirects();

Fields

Code bool followRedirects #

Set this property to true if this connection should automatically follow redirects. The default is true.

bool followRedirects;

Code int maxRedirects #

Set this property to the maximum number of redirects to follow when followRedirects is true. If this number is exceeded the onError callback will be called with a RedirectLimitExceeded exception. The default value is 5.

int maxRedirects;