HttpClientRequest abstract class
HTTP request for a client connection.
This object has a number of properties for setting up the HTTP header of the request. When the header has been set up the methods from the IOSink can be used to write the actual body of the HTTP request. When one of the IOSink methods is used for the first time the request header is send. Calling any methods that will change the header after it is sent will throw an exception.
When writing string data through the IOSink the encoding used will be determined from the "charset" parameter of the "Content-Type" header.
HttpClientRequest request = ...
request.headers.contentType
= new ContentType("application", "json", charset: "utf-8");
request.write(...); // Strings written will be UTF-8 encoded.
If no charset is provided the default of ISO-8859-1 (Latin 1) will be used.
HttpClientRequest request = ...
request.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain");
request.write(...); // Strings written will be ISO-8859-1 encoded.
If an unsupported encoding is used an exception will be thrown if using one of the write methods taking a string.
abstract class HttpClientRequest implements IOSink {
/**
* The method of the request.
*/
String get method;
/**
* The uri of the request.
*/
Uri get uri;
/**
* Gets and sets the content length of the request. If the size of
* the request is not known in advance set content length to -1,
* which is also the default.
*/
int contentLength;
/**
* Returns the request headers.
*/
HttpHeaders get headers;
/**
* Cookies to present to the server (in the 'cookie' header).
*/
List<Cookie> get cookies;
/**
* Gets and sets the requested persistent connection state.
* The default value is [:true:].
*/
bool persistentConnection;
/**
* A [HttpClientResponse] future that will complete once the response is
* available. If an error occurs before the response is available, this
* future will complete with an error.
*/
Future<HttpClientResponse> get done;
/**
* Close the request for input. Returns the value of [done].
*/
Future<HttpClientResponse> close();
/**
* Set this property to [:true:] if this request should
* automatically follow redirects. The default is [:true:].
*
* Automatic redirect will only happen for "GET" and "HEAD" requests
* and only for the status codes [:HttpHeaders.MOVED_PERMANENTLY:]
* (301), [:HttpStatus.FOUND:] (302),
* [:HttpStatus.MOVED_TEMPORARILY:] (302, alias for
* [:HttpStatus.FOUND:]), [:HttpStatus.SEE_OTHER:] (303) and
* [:HttpStatus.TEMPORARY_REDIRECT:] (307). For
* [:HttpStatus.SEE_OTHER:] (303) autmatic redirect will also happen
* for "POST" requests with the method changed to "GET" when
* following the redirect.
*
* All headers added to the request will be added to the redirection
* request(s). However, any body send with the request will not be
* part of the redirection request(s).
*/
bool followRedirects;
/**
* 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;
/**
* Get information about the client connection. Returns [null] if the socket
* is not available.
*/
HttpConnectionInfo get connectionInfo;
}
Implements
Properties
final HttpConnectionInfo connectionInfo #
Get information about the client connection. Returns null if the socket
is not available.
HttpConnectionInfo get connectionInfo;
int contentLength #
Gets and sets the content length of the request. If the size of the request is not known in advance set content length to -1, which is also the default.
int contentLength
final List<Cookie> cookies #
Cookies to present to the server (in the 'cookie' header).
List<Cookie> get cookies;
final Future<HttpClientResponse> done #
A HttpClientResponse future that will complete once the response is available. If an error occurs before the response is available, this future will complete with an error.
Future<HttpClientResponse> get done;
Encoding encoding #
The Encoding used when writing strings. Depending on the underlying consumer this property might be mutable.
Encoding encoding
bool followRedirects #
Set this property to true if this request should
automatically follow redirects. The default is true.
Automatic redirect will only happen for "GET" and "HEAD" requests
and only for the status codes HttpHeaders.MOVED_PERMANENTLY
(301), HttpStatus.FOUND (302),
HttpStatus.MOVED_TEMPORARILY (302, alias for
HttpStatus.FOUND), HttpStatus.SEE_OTHER (303) and
HttpStatus.TEMPORARY_REDIRECT (307). For
HttpStatus.SEE_OTHER (303) autmatic redirect will also happen
for "POST" requests with the method changed to "GET" when
following the redirect.
All headers added to the request will be added to the redirection request(s). However, any body send with the request will not be part of the redirection request(s).
bool followRedirects
final HttpHeaders headers #
Returns the request headers.
HttpHeaders get headers;
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
Methods
abstract void add(List<int> data) #
Writes the bytes uninterpreted to the consumer.
abstract Future addStream(Stream<List<int>> stream) #
Adds all elements of the given
stream to this.
abstract Future<HttpClientResponse> close() #
Close the request for input. Returns the value of done.
abstract void write(Object obj) #
Converts
obj to a String by invoking toString and adds the result to
this.
abstract void writeAll(Iterable objects, [String separator = ""]) #
Iterates over the given
objects and writes them in sequence.
abstract void writeCharCode(int charCode) #
Writes the
charCode to this.
This method is equivalent to write(new String.fromCharCode(charCode)).
abstract void writeln([Object obj = ""]) #
Converts
obj to a String by invoking toString and adds the result to
this. Then adds a new line.