Dev.Opera - Follow the standards, break the rulesDev.Opera - Follow the standards, break the rules

Login

Lost password?



Class WebServerResponse

Object
   |
   +--WebServerResponse

class 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.


Defined in unite.js


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

chunked

boolean chunked
Whether or not to use chunked encoding in the response.

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.


closed

boolean closed
Whether or not this response has been closed. This property mirrors the WebServerConnection.closed property.

connection

WebServerConnection connection
Connection this response will be sent to.

implicitFlush

boolean implicitFlush
Whether or not to flush data written to the response automatically.

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

WebServerResponse()
This class has no public constructor.

Method Detail

close

void close( <Function> callback )
Close the connection.

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.

Parameters:
callback - Function to call when the connection is closed. Optional.

closeAndRedispatch

void closeAndRedispatch()
Close the connection and redispatch the request to the Web server.

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.

Throws:
- INVALID_STATE_ERR If data has been written to this response before it is redispatched.

flush

void flush( <Function> callback )
Flush the data in the response.

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.

Parameters:
callback - Function to call when the response is flushed. Optional.

setProtocolString

void setProtocolString( <String> protocolString )
Set the protocol version string of the response.

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.

Parameters:
protocolString - Protocol string to set.
Throws:
- INVALID_STATE_ERR If data has been written to the response before setting the protocol string.

setResponseHeader

void setResponseHeader( <String> name, <String> value )
Set a HTTP response header.

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.

Parameters:
name - Name of the HTTP response header to set, e.g. "Content-type"
value - Value to set for the given HTTP response header.
Throws:
- INVALID_STATE_ERR If data has been written to the response before setting any headers.

setStatusCode

void setStatusCode( <String> statusCode, <String> text )
Set the HTTP status code of the response.

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.

Parameters:
statusCode - Status code to set, e.g. 200 or 404
text - Status text to set, e.g. "Success" or "Out of pidgeons". Optional.
Throws:
- INVALID_STATE_ERR If data has been written to the response before setting the status code.

write

void write( <String> data )
Write data to the response.
Parameters:
data - String of data to write.

writeBytes

void writeBytes( <ByteArray> data )
Write binary data to the response. This method takes an ECMA 4 ByteArray object and writes it to the response.
Parameters:
data - Binary data to write

writeFile

void writeFile( <File> file )
Write a File to the response. This methods takes a File object and writes the contents of the file to the response.
Parameters:
file - File object to write

writeImage

void writeImage( <HTMLImageElement> image )
Write an image to the response. The image can either be an 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.
Parameters:
image - HTML Image element or Canvas element to write.

writeLine

void writeLine( data )
Write data to the response and append a newline.
Parameters:
data - String of data to write.



Documentation generated by JSDoc on Tue Oct 6 11:14:47 2009

Libraries