|
Unite API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Object | +--WebServerResponse
Response from the Web server.
The WebServerResponse allows the user to write data back to the client which made a request. It supports
writing string data, bytes of binary data and images.
| Field Summary | |
boolean |
chunked
Whether or not to use chunked encoding in the response. |
boolean |
closed
Whether or not this response has been closed. |
WebServerConnection |
connection
Connection this response will be sent to. |
boolean |
implicitFlush
Whether or not to flush data written to the response automatically. |
| Constructor Summary | |
WebServerResponse()
This class has no public constructor. |
|
| Method Summary | |
void
|
close( <Function> callback )
Close the connection. |
void
|
closeAndRedispatch()
Close the connection and redispatch the request to the Web server. |
void
|
flush( <Function> callback )
Flush the data in the response. |
void
|
setProtocolString( <String> protocolString )
Set the protocol version string of the response. |
void
|
setResponseHeader( <String> name, <String> value )
Set a HTTP response header. |
void
|
setStatusCode( <String> statusCode, <String> text )
Set the HTTP status code of the response. |
void
|
write( <String> data )
Write data to the response. |
void
|
writeBytes( <ByteArray> data )
Write binary data to the response. |
void
|
writeFile( <File> file )
Write a File to the response. |
void
|
writeImage( <HTMLImageElement> image )
Write an image to the response. |
void
|
writeLine( data )
Write data to the response and append a newline. |
| Field Detail |
boolean chunked
Chunked encoding is used when you don't know the length of the encoding when starting to send data and to avoid frequently closing and reopening connections. It is only recommended to turn this off if clients are not expected to support chunked encoding.
This property defaults to true.
boolean closed
WebServerConnection connection
boolean implicitFlush
By default, you need to explicitly call response.flush() in order to
actually send data written to the response. By setting this property
to true, data are flushed immediately when they are written.
This property defaults to false.
| Constructor Detail |
WebServerResponse()
| Method Detail |
void close( <Function> callback )
Close the connection and set the WebServerConnection.closed property of the
corresponding WebServerConnection object to false. No writing to the
the response is possible after close() is called.
Closing is by default an asynchronous operation. You may catch when the connection actually closes by supplying an optional callback parameter.
callback - Function to call when the connection is closed. Optional.
void closeAndRedispatch()
Close the connection and put the request back into the request queue of
the Web server. The uri property of the WebServerRequest may be rewritten
for this purpose. See the WebServerRequest.uri property.
If you have set the status code or added any headers to this response,
these will be sent with the new request. But if you redispatch after having
written to the response it will fail with a INVALID_STATE_ERR.
If WebServerRequest.uri is not changed, redispatching the request will bypass any JavaScript event listeners in the next run. If the URI points to a shared file, this file will be served. Otherwise a 404 will be shown to the user.
void flush( <Function> callback )
Flush the data in the response and send them to the client immediately. Used in combination with chunked encoding, where each flush sends a chunk to the client.
Flushing is by default an asynchronous operation. You may catch when the
the response is actually flushed by supplying an optional callback parameter.
callback - Function to call when the response is flushed. Optional.
void setProtocolString( <String> protocolString )
Usually the protocol version string will contain a version of HTTP, but it can be used to set other protocols as well.
Note that you must set a protocol string before you start writing to the response. Failure to do so will result in an INVALID_STATE_ERR.
protocolString - Protocol string to set.
void setResponseHeader( <String> name, <String> value )
Use this method to specify response headers sent back to the client.
For example setting the content type to XML, by doing:
response.setResponseHeader( "Content-type", "text/html" );
Note that you must set any headers before you start writing to the response. Failure to do so will result in an INVALID_STATE_ERR.
name - Name of the HTTP response header to set, e.g. "Content-type"
value - Value to set for the given HTTP response header.
void setStatusCode( <String> statusCode, <String> text )
This method sets the status code sent back to the client, such as 404 (Not found), 200 (OK), etc. An optional argument can be used to set a specific response text as well, allowing for messages not in the HTTP specification.
If you do not set a status code, a 200 (OK) status code is silently set.
Note that you must set any status before you start writing to the response. Failure to do so will result in an INVALID_STATE_ERR.
statusCode - Status code to set, e.g. 200 or 404
text - Status text to set, e.g. "Success" or "Out of pidgeons". Optional.
void write( <String> data )
data - String of data to write.
void writeBytes( <ByteArray> data )
ByteArray object and
writes it to the response.data - Binary data to write
void writeFile( <File> file )
File object and writes the
contents of the file to the response.file - File object to write
void writeImage( <HTMLImageElement> image )
HTMLImageElement or an HTMLCanvasElement object.
In both cases the image or data referenced is serialized and written to the
response, encoded as a PNG image.image - HTML Image element or Canvas element to write.
void writeLine( data )
data - String of data to write.
|
Unite API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||