Package io.vertx.ext.web
Interface RequestBody
-
public interface RequestBody
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default JsonArray
asJsonArray()
JsonArray
asJsonArray(int maxAllowedLength)
Gets the current body buffer as aJsonArray
.default JsonObject
asJsonObject()
JsonObject
asJsonObject(int maxAllowedLength)
Gets the current body buffer as aJsonObject
.default <R> R
asPojo(Class<R> clazz)
<R> R
asPojo(Class<R> clazz, int maxAllowedLength)
String
asString()
String
asString(String encoding)
Get the entire HTTP request body as a string, assuming the specified encoding.boolean
available()
Returntrue
if aBodyHandler
was executed before this call in the lifetime of the request.Buffer
buffer()
default boolean
isEmpty()
A body can be empty if it is not available, or its length is0
.int
length()
Returns the total length of the body buffer.
-
-
-
Method Detail
-
asString
String asString()
- Returns:
- the entire HTTP request body as a string, assuming UTF-8 encoding if the request does not provide the
content type charset attribute. If a charset is provided in the request that it shall be respected. The context
must have first been routed to a
BodyHandler
for this to be populated.
-
asString
String asString(String encoding)
Get the entire HTTP request body as a string, assuming the specified encoding. The context must have first been routed to aBodyHandler
for this to be populated.- Parameters:
encoding
- the encoding, e.g. "UTF-16"- Returns:
- the body
-
asJsonObject
JsonObject asJsonObject(int maxAllowedLength)
Gets the current body buffer as aJsonObject
. If a positive limit is provided the parsing will only happen if the buffer length is smaller or equal to the limit. Otherwise anIllegalStateException
is thrown. When the application is only handling uploads in JSON format, it is recommended to set a limit onBodyHandler.setBodyLimit(long)
as this will avoid the upload to be parsed and loaded into the application memory.- Parameters:
maxAllowedLength
- if the current buffer length is greater than the limit anIllegalStateException
is thrown. This can be used to avoid DDoS attacks on very long JSON payloads that could take over the CPU while attempting to parse the data.- Returns:
- Get the entire HTTP request body as a
JsonObject
. The context must have first been routed to aBodyHandler
for this to be populated.
When the body isnull
or the"null"
JSON literal thennull
is returned.
-
asJsonArray
JsonArray asJsonArray(int maxAllowedLength)
Gets the current body buffer as aJsonArray
. If a positive limit is provided the parsing will only happen if the buffer length is smaller or equal to the limit. Otherwise anIllegalStateException
is thrown. When the application is only handling uploads in JSON format, it is recommended to set a limit onBodyHandler.setBodyLimit(long)
as this will avoid the upload to be parsed and loaded into the application memory.- Parameters:
maxAllowedLength
- if the current buffer length is greater than the limit anIllegalStateException
is thrown. This can be used to avoid DDoS attacks on very long JSON payloads that could take over the CPU while attempting to parse the data.- Returns:
- Get the entire HTTP request body as a
JsonArray
. The context must have first been routed to aBodyHandler
for this to be populated.
When the body isnull
or the"null"
JSON literal thennull
is returned.
-
asJsonObject
default JsonObject asJsonObject()
- Returns:
- Get the entire HTTP request body as a
JsonObject
. The context must have first been routed to aBodyHandler
for this to be populated.
When the body isnull
or the"null"
JSON literal thennull
is returned.
-
asJsonArray
default JsonArray asJsonArray()
- Returns:
- Get the entire HTTP request body as a
JsonArray
. The context must have first been routed to aBodyHandler
for this to be populated.
When the body isnull
or the"null"
JSON literal thennull
is returned.
-
buffer
Buffer buffer()
- Returns:
- Get the entire HTTP request body as a
Buffer
. The context must have first been routed to aBodyHandler
for this to be populated.
-
asPojo
<R> R asPojo(Class<R> clazz, int maxAllowedLength)
- Parameters:
maxAllowedLength
- if the current buffer length is greater than the limit anIllegalStateException
is thrown. This can be used to avoid DDoS attacks on very long JSON payloads that could take over the CPU while attempting to parse the data.- Returns:
- Get the entire HTTP request body as a POJO. The context must have first been routed to a
BodyHandler
for this to be populated.
When the body isnull
or the"null"
JSON literal thennull
is returned. WARNING: This feature requires jackson-databind. Or another JSON codec that implements POJO parsing
-
asPojo
default <R> R asPojo(Class<R> clazz)
- Returns:
- Get the entire HTTP request body as a POJO. The context must have first been routed to a
BodyHandler
for this to be populated.
When the body isnull
or the"null"
JSON literal thennull
is returned. WARNING: This feature requires jackson-databind. Or another JSON codec that implements POJO parsing
-
length
int length()
Returns the total length of the body buffer. This is the length in bytes. When there is no buffer the length is-1
.- Returns:
- length in bytes.
-
isEmpty
default boolean isEmpty()
A body can be empty if it is not available, or its length is0
.- Returns:
true
if empty.
-
available
boolean available()
Returntrue
if aBodyHandler
was executed before this call in the lifetime of the request.- Returns:
true
if body was parsed during the duration of the request.
-
-