Dart API Referencedart:ioHttpResponse

HttpResponse abstract class

HTTP response to be send back to the client.

abstract class HttpResponse {
  /**
   * Gets and sets the content length of the response. If the size of
   * the response is not known in advance set the content length to
   * -1 - which is also the default if not set.
   */
  int contentLength;

  /**
   * Gets and sets the status code. Any integer value is accepted. For
   * the official HTTP status codes use the fields from
   * [HttpStatus]. If no status code is explicitly set the default
   * value [HttpStatus.OK] is used.
   */
  int statusCode;

  /**
   * Gets and sets the reason phrase. If no reason phrase is explicitly
   * set a default reason phrase is provided.
   */
  String reasonPhrase;

  /**
   * Gets and sets the persistent connection state. The initial value
   * of this property is the persistent connection state from the
   * request.
   */
  bool persistentConnection;

  /**
   * Returns the response headers.
   */
  HttpHeaders get headers;

  /**
   * Cookies to set in the client (in the Set-Cookie header).
   */
  List<Cookie> get cookies;

  /**
   * Returns the output stream for the response. This is used to write
   * the response data. When all response data has been written close
   * the stream to indicate the end of the response.
   *
   * When this is accessed for the first time the response header is
   * send. Calling any methods that will change the header after
   * having retrieved the output stream will throw an exception.
   */
  OutputStream get outputStream;

  /**
   * Detach the underlying socket from the HTTP server. When the
   * socket is detached the HTTP server will no longer perform any
   * operations on it.
   *
   * This is normally used when a HTTP upgrade request is received
   * and the communication should continue with a different protocol.
   */
  DetachedSocket detachSocket();

  /**
   * Get information about the client connection. Returns [null] if the socket
   * isn't available.
   */
  HttpConnectionInfo get connectionInfo;
}

Properties

final HttpConnectionInfo connectionInfo #

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

HttpConnectionInfo get connectionInfo;

int contentLength #

Gets and sets the content length of the response. If the size of the response is not known in advance set the content length to -1 - which is also the default if not set.

int contentLength;

final List<Cookie> cookies #

Cookies to set in the client (in the Set-Cookie header).

List<Cookie> get cookies;

final HttpHeaders headers #

Returns the response headers.

HttpHeaders get headers;

final OutputStream outputStream #

Returns the output stream for the response. This is used to write the response data. When all response data has been written close the stream to indicate the end of the response.

When this is accessed for the first time the response header is send. Calling any methods that will change the header after having retrieved the output stream will throw an exception.

OutputStream get outputStream;

bool persistentConnection #

Gets and sets the persistent connection state. The initial value of this property is the persistent connection state from the request.

bool persistentConnection;

String reasonPhrase #

Gets and sets the reason phrase. If no reason phrase is explicitly set a default reason phrase is provided.

String reasonPhrase;

int statusCode #

Gets and sets the status code. Any integer value is accepted. For the official HTTP status codes use the fields from HttpStatus. If no status code is explicitly set the default value HttpStatus.OK is used.

int statusCode;

Methods

DetachedSocket detachSocket() #

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

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

DetachedSocket detachSocket();