|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.vertx.groovy.core.http.HttpServerResponse
class HttpServerResponse
Represents a server-side HTTP response.
An instance of this class is created and associated to every instance of HttpServerRequest that is created.
It allows the developer to control the HTTP response that is sent back to the client for a partcularHTTP request. It contains methods that allow HTTP headers and trailers to be set, and for a body to be written out to the response.
It also allows files to be streamed by the kernel directly from disk to the outgoing HTTP connection, bypassing user space altogether (where supported by the underlying operating system). This is a very efficient way of serving files from the server since buffers do not have to be read one by one from the file and written to the outgoing socket.
It implements WriteStream so it can be used with Pump to pump data with flow control.
Instances of this class are not thread-safe
Constructor Summary | |
protected HttpServerResponse(HttpServerResponse jResponse)
|
Method Summary | |
---|---|
void
|
close()
Close the underlying TCP connection |
void
|
closeHandler(groovy.lang.Closure handler)
Set a close handler for the response. |
void
|
drainHandler(groovy.lang.Closure handler)
{@inheritDoc} |
void
|
end(java.lang.String chunk)
Same as end(Buffer) but writes a String with the default encoding |
void
|
end(java.lang.String chunk, java.lang.String enc)
Same as end(Buffer) but writes a String with the specified encoding |
void
|
end(Buffer chunk)
Same as end() but writes some data to the response body before ending. |
void
|
end()
Ends the response. |
void
|
exceptionHandler(groovy.lang.Closure handler)
{@inheritDoc} |
java.util.Map
|
getHeaders()
@return The headers of the response |
int
|
getStatusCode()
|
java.lang.String
|
getStatusMessage()
|
java.util.Map
|
getTrailers()
@return The trailers of the response |
boolean
|
isWriteQueueFull()
{@inheritDoc} |
HttpServerResponse
|
leftShift(Buffer buff)
Same as write(Buffer) |
HttpServerResponse
|
leftShift(java.lang.String str)
Same as write(String) |
HttpServerResponse
|
putHeader(java.lang.String name, java.lang.Object value)
Put an HTTP header - fluent API |
HttpServerResponse
|
sendFile(java.lang.String filename)
Tell the kernel to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. |
HttpServerResponse
|
setChunked(boolean chunked)
If chunked is true, this response will use HTTP chunked encoding, and each call to write to the body will correspond to a new HTTP chunk sent on the wire. |
void
|
setStatusCode(int code)
Set the status code |
void
|
setStatusMessage(java.lang.String msg)
Set the status message |
void
|
setWriteQueueMaxSize(int size)
{@inheritDoc} |
HttpServerResponse
|
write(Buffer chunk)
Write a Buffer to the response body. |
HttpServerResponse
|
write(java.lang.String chunk, java.lang.String enc)
Write a java.lang.String to the response body, encoded using the encoding enc. |
HttpServerResponse
|
write(java.lang.String chunk)
Write a java.lang.String to the response body, encoded in UTF-8. |
HttpServerResponse
|
write(Buffer chunk, groovy.lang.Closure doneHandler)
Write a Buffer to the response body. |
HttpServerResponse
|
write(java.lang.String chunk, java.lang.String enc, groovy.lang.Closure doneHandler)
Write a java.lang.String to the response body, encoded with encoding enc. |
HttpServerResponse
|
write(java.lang.String chunk, groovy.lang.Closure doneHandler)
Write a java.lang.String to the response body, encoded in UTF-8. |
void
|
writeBuffer(Buffer chunk)
{@inheritDoc} |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Constructor Detail |
---|
protected HttpServerResponse(HttpServerResponse jResponse)
Method Detail |
---|
void close()
void closeHandler(groovy.lang.Closure handler)
void drainHandler(groovy.lang.Closure handler)
void end(java.lang.String chunk)
void end(java.lang.String chunk, java.lang.String enc)
void end(Buffer chunk)
void end()
Once the response has ended, it cannot be used any more.
void exceptionHandler(groovy.lang.Closure handler)
java.util.Map getHeaders()
int getStatusCode()
java.lang.String getStatusMessage()
java.util.Map getTrailers()
boolean isWriteQueueFull()
HttpServerResponse leftShift(Buffer buff)
HttpServerResponse leftShift(java.lang.String str)
HttpServerResponse putHeader(java.lang.String name, java.lang.Object value)
name
- The header namevalue
- The header value
HttpServerResponse sendFile(java.lang.String filename)
HttpServerResponse setChunked(boolean chunked)
If chunked is false, this response will not use HTTP chunked encoding, and therefore if any data is written the body of the response, the total size of that data must be set in the Content-Length header before any data is written to the response body.
An HTTP chunked response is typically used when you do not know the total size of the request body up front.
void setStatusCode(int code)
code
- The code
void setStatusMessage(java.lang.String msg)
msg
- The message
void setWriteQueueMaxSize(int size)
HttpServerResponse write(Buffer chunk)
HttpServerResponse write(java.lang.String chunk, java.lang.String enc)
HttpServerResponse write(java.lang.String chunk)
HttpServerResponse write(Buffer chunk, groovy.lang.Closure doneHandler)
HttpServerResponse write(java.lang.String chunk, java.lang.String enc, groovy.lang.Closure doneHandler)
HttpServerResponse write(java.lang.String chunk, groovy.lang.Closure doneHandler)
void writeBuffer(Buffer chunk)
Groovy Documentation