public interface ServerHttpExchange
| Modifier and Type | Method and Description |
|---|---|
ServerHttpExchange |
bodyAction(Action<?> action)
Attaches an action to be called with the whole request body.
|
ServerHttpExchange |
chunkAction(Action<?> action)
Attaches an action to be called with a chunk from the request body.
|
ServerHttpExchange |
closeAction(Action<Void> action)
Attaches an action to be called when both request and response end
successfully or the underlying connection is aborted for some reason like
an error.
|
ServerHttpExchange |
end()
Completes the response.
|
ServerHttpExchange |
end(ByteBuffer byteBuffer)
Writes a binary chunk to the response body and completes the response
through
end(). |
ServerHttpExchange |
end(String data)
Writes a text chunk to the response body using the charset from the
response header,
content-type and completes the response through
end(). |
ServerHttpExchange |
end(String data,
String charsetName)
Writes a text chunk to the response body using the given charset and
completes the response through
end(). |
ServerHttpExchange |
endAction(Action<Void> action)
Attaches an action to be called when the request is fully read.
|
ServerHttpExchange |
errorAction(Action<Throwable> action)
Attaches an action to be called when this exchange gets an error.
|
String |
header(String name)
Returns the first request header associated with the given name.
|
Set<String> |
headerNames()
The names of the request headers.
|
List<String> |
headers(String name)
Returns the request headers associated with the given name or empty list
if no header is found.
|
String |
method()
The name of the request method.
|
ServerHttpExchange |
read()
Reads the request body.
|
ServerHttpExchange |
readAsBinary()
Reads the request body as binary.
|
ServerHttpExchange |
readAsText()
Reads the request body as text.
|
ServerHttpExchange |
readAsText(String charsetName)
Reads the request body as text using the given charset.
|
ServerHttpExchange |
setHeader(String name,
Iterable<String> value)
Sets response headers.
|
ServerHttpExchange |
setHeader(String name,
String value)
Sets a response header.
|
ServerHttpExchange |
setStatus(HttpStatus status)
Sets the HTTP status for the response.
|
<T> T |
unwrap(Class<T> clazz)
Returns the provider-specific component.
|
String |
uri()
The request URI.
|
ServerHttpExchange |
write(ByteBuffer byteBuffer)
Writes a binary chunk to the response body.
|
ServerHttpExchange |
write(String data)
Writes a text chunk to the response body using the charset from the
response header,
content-type. |
ServerHttpExchange |
write(String data,
String charsetName)
Writes a text chunk to the response body using the given charset.
|
String uri()
String method()
Set<String> headerNames()
Set is case-sensitive.List<String> headers(String name)
ServerHttpExchange read()
content-type,
starts with text/, the body is read as text, and if not, as
binary. In case of text body, the charset is also determined by the same
header. If it's not given, ISO-8859-1 is used by default.
The read data will be passed to event handlers as String if it's
text and ByteBuffer if it's binary attached through
chunkAction(Action).
This method should be called after adding
chunkAction(Action),
bodyAction(Action), and
endAction(Action) and has no side effect if
called more than once.
ServerHttpExchange readAsText()
content-type. If it's not given, ISO-8859-1 is
used by default.
The read data will be passed to event handlers as String attached
through chunkAction(Action).
This method should be called after adding
chunkAction(Action),
bodyAction(Action), and
endAction(Action) and has no side effect if
called more than once.
ServerHttpExchange readAsText(String charsetName)
The read data will be passed to event handlers as String attached
through chunkAction(Action).
This method should be called after adding
chunkAction(Action),
bodyAction(Action), and
endAction(Action) and has no side effect if
called more than once.
ServerHttpExchange readAsBinary()
The read data will be passed to event handlers as ByteBuffer
attached through chunkAction(Action).
This method should be called after adding
chunkAction(Action),
bodyAction(Action), and
endAction(Action) and has no side effect if
called more than once.
ServerHttpExchange chunkAction(Action<?> action)
String for text body and ByteBuffer
for binary body.ServerHttpExchange endAction(Action<Void> action)
ServerHttpExchange bodyAction(Action<?> action)
String for text body and ByteBuffer for
binary body. If the body is quite big, it may drain memory quickly.ServerHttpExchange setStatus(HttpStatus status)
ServerHttpExchange setHeader(String name, String value)
ServerHttpExchange setHeader(String name, Iterable<String> value)
ServerHttpExchange write(String data)
content-type. If it's not given,
ISO-8859-1 is used.ServerHttpExchange write(String data, String charsetName)
ServerHttpExchange write(ByteBuffer byteBuffer)
ServerHttpExchange end()
ServerHttpExchange end(String data)
content-type and completes the response through
end().ServerHttpExchange end(String data, String charsetName)
end().ServerHttpExchange end(ByteBuffer byteBuffer)
end().ServerHttpExchange errorAction(Action<Throwable> action)
ServerHttpExchange closeAction(Action<Void> action)
<T> T unwrap(Class<T> clazz)
Copyright 2014, The Vibe Project