public interface ServerHttpExchange
| Modifier and Type | Method and Description |
|---|---|
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(). |
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.
|
HttpMethod |
method()
The name of the request method.
|
ServerHttpExchange |
onbody(Action<?> action)
Attaches an action to be called with the whole request body.
|
ServerHttpExchange |
onchunk(Action<?> action)
Attaches an action to be called with a chunk from the request body.
|
ServerHttpExchange |
onclose(Action<Void> action)
Attaches an action when the underlying connection is aborted for some
reason like an error.
|
ServerHttpExchange |
onend(Action<Void> action)
Attaches an action to be called when the request is fully read.
|
ServerHttpExchange |
onerror(Action<Throwable> action)
Attaches an action to be called when this exchange gets an error.
|
ServerHttpExchange |
onfinish(Action<Void> action)
Attaches an action to be called when the response is fully written.
|
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()
HttpMethod 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
onchunk(Action).
This method should be called after adding
onchunk(Action),
onbody(Action), and
onend(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 onchunk(Action).
This method should be called after adding
onchunk(Action),
onbody(Action), and
onend(Action) and has no side effect if called
more than once.ServerHttpExchange readAsText(String charsetName)
String attached
through onchunk(Action).
This method should be called after adding
onchunk(Action),
onbody(Action), and
onend(Action) and has no side effect if called
more than once.ServerHttpExchange readAsBinary()
ByteBuffer
attached through onchunk(Action).
This method should be called after adding
onchunk(Action),
onbody(Action), and
onend(Action) and has no side effect if called
more than once.ServerHttpExchange onchunk(Action<?> action)
String for text body and ByteBuffer
for binary body.ServerHttpExchange onend(Action<Void> action)
ServerHttpExchange onbody(Action<?> action)
String for text body and ByteBuffer for
binary body. If the body is quite big, it may drain memory quickly. If
that's the case, use onchunk(Action) and
onend(Action).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 onfinish(Action<Void> action)
ServerHttpExchange onerror(Action<Throwable> action)
ServerHttpExchange onclose(Action<Void> action)
<T> T unwrap(Class<T> clazz)
Copyright © 2015–2018. All rights reserved.