API Reference 1.1.0streamHttpConnect

HttpConnect abstract class

A HTTP request connection.

abstract class HttpConnect {
 /** Instantiates a connection by redirecting the output to the given buffer
  * (bytes).
  */
 factory HttpConnect.buffer(HttpConnect origin, List<int> buffer)
 => new _BufferedConnect(origin, buffer);
 /** Instantiates a connection by redirecting the output to the given
  * string buffer.
  */
 factory HttpConnect.stringBuffer(HttpConnect origin, StringBuffer buffer)
 => new _StringBufferedConnect(origin, buffer);
 /** Instantiates a connection that will be used to include or forward to
  * another request handler.
  *
  * * [uri] - the URI to chain with. If omitted, it is the same as [connect]'s.
  * It can contain the query string too.
  * * [inclusion] - whether it is used for inclusion. If true,
  * any modification to `connect.response.headers` is ignored.
  */
 factory HttpConnect.chain(HttpConnect connect, {bool inclusion: true,
     String uri, HttpRequest request, HttpResponse response}) {
   return inclusion ?
     new _IncludedConnect(connect, request, response, uri):
     new _ForwardedConnect(connect, request, response, uri);
 }

 ///The Stream server
 StreamServer get server;
 ///The channel that this connection is on.
 HttpChannel get channel;
 ///The HTTP request.
 HttpRequest get request;
 /** The HTTP response.
  *
  * Notice that you shall *NOT* invoke `response.close()`, since it was
  * called automatically when the serving of a request is finished.
  */
 HttpResponse get response;
 ///The source connection that forwards to this connection, or null if not forwarded.
 HttpConnect get forwarder;
 ///The source connection that includes this connection, or null if not included.
 HttpConnect get includer;
 /** Whether this connection is caused by inclusion.
  * Note: it is true if [includer] is not null or [forwarder] is included.
  */
 bool get isIncluded;
 /** Whether this connection is caused by forwarding.
  * Note: it is true if [forwarder] is not null or [includer] is forwarded.
  */
 bool get isForwarded;

 /** Send a temporary redirect to the specified redirect URL.
  *
  * * [url] - the location to redirect to. It can be an URI or URL, such as
  * `/login?whatever` and `http://rikulo.org/project/stream`.
  *
  * > Notice: you shall invoke this method instead of `HttpResponse.redirect()`,
  * since `HttpResponse.redirect()` will close the connection (which
  * will be called automatically under Rikulo Stream).
  */
 void redirect(String url, {int status: HttpStatus.MOVED_TEMPORARILY});

 /** Forward this connection to the given [uri].
  *
  * If [request] and/or [response] is ignored, the request and/or response
  * of this connection is assumed.
  * If [uri] is null, `connect.uri` is assumed, i.e., forwarded to the same handler.
  *
  * After calling this method, the caller shall write the output stream in `then`, since
  * the request handler for the given URI might handle it asynchronously. For example,
  *
  *     connect.forward(connect, "another").then((_) {
  *       connect.response.write("<p>More content</p>");
  *       //...
  *     });
  *
  * * [uri] - the URI to chain. If omitted, it is the same as this connection.
  * It can contain the query string too.
  *
  * ##Difference between [forward] and [include]
  *
  * [forward] and [include] are almost the same, except
  *
  * * The included request handler won't be able to generate any HTTP headers
  * (it is the job of the caller). Any updates to HTTP headers in the included
  * request handler are simply ignored.
  *
  * Notice the default implementation is `connect.forward(connect, uri...)`.
  */
 Future forward(String uri, {HttpRequest request, HttpResponse response});
 /** Includes the given [uri].
  *
  * If [request] or [response] is ignored, this connect's request or response is assumed.
  * If [uri] is null, `connect.uri` is assumed, i.e., includes the same handler.
  *
  * After calling this method, the caller shall write the output stream in `then`, since
  * the request handler for the given URI might handle it asynchronously. For example,
  *
  *     connect.include(connect, "another").then((_) {
  *       connect.response.write("<p>More content</p>");
  *       //...
  *     });
  *
  * * [uri] - the URI to chain. If omitted, it is the same as this connection.
  * It can contain the query string too.
  *
  * ##Difference between [forward] and [include]
  *
  * [forward] and [include] are almost the same, except
  *
  * * The included request handler won't be able to generate any HTTP headers
  * (it is the job of the caller). Any updates to HTTP headers in the included
  * request handler are simply ignored.
  *
  * Notice the default implementation is `connect.include(connect, uri...)`.
  */
 Future include(String uri, {HttpRequest request, HttpResponse response});

 /** The browser information.
  *
  * * See also [Browser](http://api.rikulo.org/commons/latest/rikulo_browser/Browser.html).
  */
 Browser get browser;

 /** The preferred Locale that the client will accept content in,
  * based on the Accept-Language header.
  */
 String get locale;
 /** A readonly list of Locales indicating, in decreasing order starting with
 * the preferred locale, the locales that are acceptable to the client based
 * on the Accept-Language header
 */
 List<String> get locales;

 /** The error detailed information, or null if no error occurs.
  */
 ErrorDetail errorDetail;

 /** A map of application-specific data.
  *
  * Note: the name of the keys can't start with "stream.", which is reserved
  * for internal use.
  */
 Map<String, dynamic> get dataset;
}

Subclasses

HttpConnectWrapper

Constructors

factory HttpConnect.buffer(HttpConnect origin, List<int> buffer) #

Instantiates a connection by redirecting the output to the given buffer (bytes).

factory HttpConnect.buffer(HttpConnect origin, List<int> buffer)
=> new _BufferedConnect(origin, buffer);

factory HttpConnect.chain(HttpConnect connect, {bool inclusion: true, String uri, HttpRequest request, HttpResponse response}) #

Instantiates a connection that will be used to include or forward to another request handler.

  • uri - the URI to chain with. If omitted, it is the same as connect's. It can contain the query string too.

  • inclusion - whether it is used for inclusion. If true, any modification to connect.response.headers is ignored.

factory HttpConnect.chain(HttpConnect connect, {bool inclusion: true,
   String uri, HttpRequest request, HttpResponse response}) {
 return inclusion ?
   new _IncludedConnect(connect, request, response, uri):
   new _ForwardedConnect(connect, request, response, uri);
}

factory HttpConnect.stringBuffer(HttpConnect origin, StringBuffer buffer) #

Instantiates a connection by redirecting the output to the given string buffer.

factory HttpConnect.stringBuffer(HttpConnect origin, StringBuffer buffer)
=> new _StringBufferedConnect(origin, buffer);

Properties

final Browser browser #

The browser information.

Browser get browser;

final HttpChannel channel #

The channel that this connection is on.

HttpChannel get channel;

final Map<String, dynamic> dataset #

A map of application-specific data.

Note: the name of the keys can't start with "stream.", which is reserved for internal use.

Map<String, dynamic> get dataset;

ErrorDetail errorDetail #

The error detailed information, or null if no error occurs.

ErrorDetail errorDetail

final HttpConnect forwarder #

The source connection that forwards to this connection, or null if not forwarded.

HttpConnect get forwarder;

final HttpConnect includer #

The source connection that includes this connection, or null if not included.

HttpConnect get includer;

final bool isForwarded #

Whether this connection is caused by forwarding. Note: it is true if forwarder is not null or includer is forwarded.

bool get isForwarded;

final bool isIncluded #

Whether this connection is caused by inclusion. Note: it is true if includer is not null or forwarder is included.

bool get isIncluded;

final String locale #

The preferred Locale that the client will accept content in, based on the Accept-Language header.

String get locale;

final List<String> locales #

A readonly list of Locales indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header

List<String> get locales;

final HttpRequest request #

The HTTP request.

HttpRequest get request;

final HttpResponse response #

The HTTP response.

Notice that you shall NOT invoke response.close(), since it was called automatically when the serving of a request is finished.

HttpResponse get response;

final StreamServer server #

The Stream server

StreamServer get server;

Methods

abstract Future forward(String uri, {HttpRequest request, HttpResponse response}) #

Forward this connection to the given uri.

If request and/or response is ignored, the request and/or response of this connection is assumed. If uri is null, connect.uri is assumed, i.e., forwarded to the same handler.

After calling this method, the caller shall write the output stream in then, since the request handler for the given URI might handle it asynchronously. For example,

connect.forward(connect, "another").then((_) {
  connect.response.write("<p>More content</p>");
  //...
});
  • uri - the URI to chain. If omitted, it is the same as this connection. It can contain the query string too.

Difference between forward and include

forward and include are almost the same, except

  • The included request handler won't be able to generate any HTTP headers (it is the job of the caller). Any updates to HTTP headers in the included request handler are simply ignored.

Notice the default implementation is connect.forward(connect, uri...).

abstract Future include(String uri, {HttpRequest request, HttpResponse response}) #

Includes the given uri.

If request or response is ignored, this connect's request or response is assumed. If uri is null, connect.uri is assumed, i.e., includes the same handler.

After calling this method, the caller shall write the output stream in then, since the request handler for the given URI might handle it asynchronously. For example,

connect.include(connect, "another").then((_) {
  connect.response.write("<p>More content</p>");
  //...
});
  • uri - the URI to chain. If omitted, it is the same as this connection. It can contain the query string too.

Difference between forward and include

forward and include are almost the same, except

  • The included request handler won't be able to generate any HTTP headers (it is the job of the caller). Any updates to HTTP headers in the included request handler are simply ignored.

Notice the default implementation is connect.include(connect, uri...).

abstract void redirect(String url, {int status: HttpStatus.MOVED_TEMPORARILY}) #

Send a temporary redirect to the specified redirect URL.

  • url - the location to redirect to. It can be an URI or URL, such as /login?whatever and http://rikulo.org/project/stream.

Notice: you shall invoke this method instead of HttpResponse.redirect(),

since HttpResponse.redirect() will close the connection (which will be called automatically under Rikulo Stream).