Top Description Fields Constructors Methods
org.springframework.http.codec

public Class FormHttpMessageReader

extends LoggingCodecSupport
implements HttpMessageReader<MultiValueMap<String, String>>
Class Inheritance
All Implemented Interfaces
org.springframework.http.codec.HttpMessageReader
Imports
java.net.URLDecoder, java.nio.charset.Charset, .StandardCharsets, java.util.Collections, .List, .Map, reactor.core.publisher.Flux, .Mono, org.springframework.core.ResolvableType, org.springframework.core.codec.Hints, org.springframework.core.io.buffer.DataBufferLimitException, .DataBufferUtils, org.springframework.core.log.LogFormatUtils, org.springframework.http.MediaType, .ReactiveHttpInputMessage, org.springframework.lang.Nullable, org.springframework.util.Assert, .LinkedMultiValueMap, .MultiValueMap, .StringUtils

Implementation of an HttpMessageReader to read HTML form data, i.e. request body with media type "application/x-www-form-urlencoded".
Authors
Sebastien Deleuze, Rossen Stoyanchev
Since
5.0

Field Summary

Modifier and TypeField and Description
public static final Charset
DEFAULT_CHARSET

The default charset used by the reader.

private Charset
private int
private static final ResolvableType
Inherited from org.springframework.http.codec.LoggingCodecSupport:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
canRead(ResolvableType
the type of object to check
elementType
,
MediaType
the media type for the read (possibly null)
mediaType
)

Implements org.springframework.http.codec.HttpMessageReader.canRead.

Whether the given object type is supported by this reader.

public Charset
getDefaultCharset()

Return the configured default charset.

public int
getMaxInMemorySize()

Return the configured byte count limit.

private Charset
public List<MediaType>
getReadableMediaTypes()

Implements org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Return the list of media types supported by this reader.

private void
private MultiValueMap<String, String>
parseFormData(Charset charset, String body)

public Flux<MultiValueMap<String, String>>
read(ResolvableType
the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)
elementType
,
ReactiveHttpInputMessage
the message to read from
message
,
Map<String, Object>
additional information about how to read and decode the input
hints
)

Implements org.springframework.http.codec.HttpMessageReader.read.

Read from the input message and decode to a stream of objects.

public Mono<MultiValueMap<String, String>>
readMono(ResolvableType
the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)
elementType
,
ReactiveHttpInputMessage
the message to read from
message
,
Map<String, Object>
additional information about how to read and decode the input
hints
)

Implements org.springframework.http.codec.HttpMessageReader.readMono.

Read from the input message and decode to a single object.

public void
setDefaultCharset(Charset charset)

Set the default character set to use for reading form data when the request Content-Type header does not explicitly specify it.

public void
setMaxInMemorySize(int
the max number of bytes to buffer, or -1 for unlimited
byteCount
)

Set the max number of bytes for input form data.

private static boolean
Inherited from org.springframework.http.codec.LoggingCodecSupport:
isEnableLoggingRequestDetailssetEnableLoggingRequestDetails

Field Detail

DEFAULT_CHARSETback to summary
public static final Charset DEFAULT_CHARSET

The default charset used by the reader.

defaultCharsetback to summary
private Charset defaultCharset
maxInMemorySizeback to summary
private int maxInMemorySize
MULTIVALUE_STRINGS_TYPEback to summary
private static final ResolvableType MULTIVALUE_STRINGS_TYPE

Constructor Detail

FormHttpMessageReaderback to summary
public FormHttpMessageReader()

Method Detail

canReadback to summary
public boolean canRead(ResolvableType elementType, MediaType mediaType)

Implements org.springframework.http.codec.HttpMessageReader.canRead.

Doc from org.springframework.http.codec.HttpMessageReader.canRead.

Whether the given object type is supported by this reader.

Parameters
elementType:ResolvableType

the type of object to check

mediaType:MediaType

the media type for the read (possibly null)

Returns:boolean

true if readable, false otherwise

Annotations
@Override
getDefaultCharsetback to summary
public Charset getDefaultCharset()

Return the configured default charset.

getMaxInMemorySizeback to summary
public int getMaxInMemorySize()

Return the configured byte count limit.

Since
5.1.11
getMediaTypeCharsetback to summary
private Charset getMediaTypeCharset(MediaType mediaType)
getReadableMediaTypesback to summary
public List<MediaType> getReadableMediaTypes()

Implements org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Doc from org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Return the list of media types supported by this reader. The list may not apply to every possible target element type and calls to this method should typically be guarded via canWrite(elementType, null). The list may also exclude media types supported only for a specific element type. Alternatively, use getReadableMediaTypes(ResolvableType) for a more precise list.

Returns:List<MediaType>

the general list of supported media types

Annotations
@Override
logFormDataback to summary
private void logFormData(MultiValueMap<String, String> formData, Map<String, Object> hints)
parseFormDataback to summary
private MultiValueMap<String, String> parseFormData(Charset charset, String body)
readback to summary
public Flux<MultiValueMap<String, String>> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints)

Implements org.springframework.http.codec.HttpMessageReader.read.

Doc from org.springframework.http.codec.HttpMessageReader.read.

Read from the input message and decode to a stream of objects.

Parameters
elementType:ResolvableType

the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)

message:ReactiveHttpInputMessage

the message to read from

hints:Map<String, Object>

additional information about how to read and decode the input

Returns:Flux<MultiValueMap<String, String>>

the decoded stream of elements

Annotations
@Override
readMonoback to summary
public Mono<MultiValueMap<String, String>> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints)

Implements org.springframework.http.codec.HttpMessageReader.readMono.

Doc from org.springframework.http.codec.HttpMessageReader.readMono.

Read from the input message and decode to a single object.

Parameters
elementType:ResolvableType

the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)

message:ReactiveHttpInputMessage

the message to read from

hints:Map<String, Object>

additional information about how to read and decode the input

Returns:Mono<MultiValueMap<String, String>>

the decoded object

Annotations
@Override
setDefaultCharsetback to summary
public void setDefaultCharset(Charset charset)

Set the default character set to use for reading form data when the request Content-Type header does not explicitly specify it.

By default this is set to "UTF-8".

setMaxInMemorySizeback to summary
public void setMaxInMemorySize(int byteCount)

Set the max number of bytes for input form data. As form data is buffered before it is parsed, this helps to limit the amount of buffering. Once the limit is exceeded, DataBufferLimitException is raised.

By default this is set to 256K.

Parameters
byteCount:int

the max number of bytes to buffer, or -1 for unlimited

Since
5.1.11
supportsMediaTypeback to summary
private static boolean supportsMediaType(MediaType mediaType)