Top Description Inners Fields Constructors Methods
io.netty.handler.codec.http.multipart

public Class HttpPostRequestEncoder

extends Object
implements ChunkedInput<HttpContent>
Class Inheritance
All Implemented Interfaces
io.netty.handler.stream.ChunkedInput
Imports
io.netty.buffer.ByteBuf, .ByteBufAllocator, io.netty.channel.ChannelHandlerContext, io.netty.handler.codec.DecoderResult, io.netty.handler.codec.http.DefaultFullHttpRequest, .DefaultHttpContent, .EmptyHttpHeaders, .FullHttpRequest, .HttpConstants, .HttpContent, .HttpHeaderNames, .HttpHeaderValues, .HttpHeaders, .HttpMethod, .HttpRequest, .HttpUtil, .HttpVersion, .LastHttpContent, io.netty.handler.stream.ChunkedInput, io.netty.util.internal.ObjectUtil, .PlatformDependent, .StringUtil, java.io.File, .IOException, .UnsupportedEncodingException, java.net.URLEncoder, java.nio.charset.Charset, java.util.ArrayList, .List, .ListIterator, .Map, java.util.regex.Pattern

This encoder will help to encode Request for a FORM as POST.

According to RFC 7231, POST, PUT and OPTIONS allow to have a body. This encoder will support widely all methods except TRACE since the RFC notes for GET, DELETE, HEAD and CONNECT: (replaces XXX by one of these methods)

"A payload within a XXX request message has no defined semantics; sending a payload body on a XXX request might cause some existing implementations to reject the request."

On the contrary, for TRACE method, RFC says:

"A client MUST NOT send a message body in a TRACE request."

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
HttpPostRequestEncoder.EncoderMode

Different modes to use to encode form data.

public static class
HttpPostRequestEncoder.ErrorDataEncoderException

Exception when an error occurs while encoding

private static class
private static class

Field Summary

Modifier and TypeField and Description
private final List<InterfaceHttpData>
bodyListDatas

InterfaceHttpData for Body (without encoding)

private final Charset
charset

Default charset to use

private ByteBuf
currentBuffer

The ByteBuf currently used by the encoder

private InterfaceHttpData
currentData

The current InterfaceHttpData to encode (used if more chunks are available)

private FileUpload
currentFileUpload

The current FileUpload that is currently in encode process

private boolean
duringMixedMode

While adding a FileUpload, is the multipart currently in Mixed Mode

private final HttpPostRequestEncoder.EncoderMode
private final HttpDataFactory
factory

Factory used to create InterfaceHttpData

private long
globalBodySize

Global Body size

private long
globalProgress

Global Transfer progress

private boolean
headerFinalized

To check if the header has been finalized

private boolean
isChunked

Chunked false by default

private boolean
isKey

If not multipart, does the currentBuffer stands for the Key or for the Value

private boolean
isLastChunk

Does the last non empty chunk already encoded so that next chunk will be empty (last chunk)

private boolean
isLastChunkSent

Last chunk already sent

private final boolean
isMultipart

Does this request is a Multipart request

private ListIterator<InterfaceHttpData>
iterator

Iterator to be used when encoding will be called chunk after chunk

pack-priv String
multipartDataBoundary

If multipart, this is the boundary for the flobal multipart

pack-priv final List<InterfaceHttpData>
multipartHttpDatas

The final Multipart List of InterfaceHttpData including encoding

pack-priv String
multipartMixedBoundary

If multipart, there could be internal multiparts (mixed) to the global multipart.

private static final Map.Entry<K, V>[]
private final HttpRequest
request

Request to encode

Constructor Summary

AccessConstructor and Description
public
HttpPostRequestEncoder(HttpRequest
the request to encode
request
,
boolean
True if the FORM is a ENCTYPE="multipart/form-data"
multipart
)

public
HttpPostRequestEncoder(HttpDataFactory
the factory used to create InterfaceHttpData
factory
,
HttpRequest
the request to encode
request
,
boolean
True if the FORM is a ENCTYPE="multipart/form-data"
multipart
)

public
HttpPostRequestEncoder(HttpDataFactory
the factory used to create InterfaceHttpData
factory
,
HttpRequest
the request to encode
request
,
boolean
True if the FORM is a ENCTYPE="multipart/form-data"
multipart
,
Charset
the charset to use as default
charset
,
HttpPostRequestEncoder.EncoderMode
the mode for the encoder to use. See EncoderMode for the details.
encoderMode
)

Method Summary

Modifier and TypeMethod and Description
public void
addBodyAttribute(String
name of the parameter
name
,
String
the value of the parameter
value
)

Add a simple attribute in the body as Name=Value

public void
addBodyFileUpload(String
the name of the parameter
name
,
File
the file to be uploaded (if not Multipart mode, only the filename will be included)
file
,
String
the associated contentType for the File
contentType
,
boolean
True if this file should be transmitted in Text format (else binary)
isText
)

Add a file as a FileUpload

public void
addBodyFileUpload(String
the name of the parameter
name
,
String
the filename to use for this File part, empty String will be ignored by the encoder
filename
,
File
the file to be uploaded (if not Multipart mode, only the filename will be included)
file
,
String
the associated contentType for the File
contentType
,
boolean
True if this file should be transmitted in Text format (else binary)
isText
)

Add a file as a FileUpload

public void
addBodyFileUploads(String
the name of the parameter
name
,
File[]
the array of files
file
,
String[]
the array of content Types associated with each file
contentType
,
boolean[]
the array of isText attribute (False meaning binary mode) for each file
isText
)

Add a series of Files associated with one File parameter

public void
addBodyHttpData(InterfaceHttpData data)

Add the InterfaceHttpData to the Body list

private int
public void
cleanFiles()

Clean all HttpDatas (on Disk) for the current request.

public void
close()

Implements io.netty.handler.stream.ChunkedInput.close.

Releases the resources associated with the input.
private String

Returns:

the encoded attribute
encodeAttribute
(String s, Charset charset)

Encode one attribute

private HttpContent

Returns:

the next HttpChunk or null if not enough bytes were found
encodeNextChunkMultipart
(int
the number of bytes to try to get from currentData
sizeleft
)

From the current context (currentBuffer and currentData), returns the next HttpChunk (if possible) trying to get sizeleft bytes more into the currentBuffer.

private HttpContent

Returns:

the next HttpChunk or null if not enough bytes were found
encodeNextChunkUrlEncoded
(int
the number of bytes to try to get from currentData
sizeleft
)

From the current context (currentBuffer and currentData), returns the next HttpChunk (if possible) trying to get sizeleft bytes more into the currentBuffer.

private ByteBuf

Returns:

the next ByteBuf to send as an HttpChunk and modifying currentBuffer accordingly
fillByteBuf
()

public HttpRequest

Returns:

the request object (chunked or not according to size of body)
finalizeRequest
()

Finalize the request by preparing the Header in the request and returns the request ready to be sent.

public List<InterfaceHttpData>

Returns:

the list of InterfaceHttpData from Body part
getBodyListAttributes
()

This getMethod returns a List of all InterfaceHttpData from body part.

private static String

Returns:

a newly generated Delimiter (either for DATA or MIXED)
getNewMultipartDelimiter
()

private void
initDataMultipart()

Init the delimiter for Global Part (Data).

private void
initMixedMultipart()

Init the delimiter for Mixed Part (Mixed).

public boolean

Returns:

True if the request is by Chunk
isChunked
()

public boolean
isEndOfInput()

Implements io.netty.handler.stream.ChunkedInput.isEndOfInput.

Return true if and only if there is no data left in the stream and the stream has reached at its end.
public boolean

Returns:

True if this request is a Multipart request
isMultipart
()

True if this request is a Multipart request

private HttpContent
public long
length()

Implements io.netty.handler.stream.ChunkedInput.length.

Returns the length of the input.
private HttpContent

Returns:

the next available HttpChunk
nextChunk
()

Returns the next available HttpChunk.

public long
progress()

Implements io.netty.handler.stream.ChunkedInput.progress.

Returns current transfer progress.
public HttpContent
readChunk(ChannelHandlerContext
The context which provides a ByteBufAllocator if buffer allocation is necessary.
ctx
)

Implements io.netty.handler.stream.ChunkedInput.readChunk.

Deprecated
public HttpContent

Returns:

the next available HttpChunk
readChunk
(ByteBufAllocator
ByteBufAllocator if buffer allocation is necessary.
allocator
)

Implements io.netty.handler.stream.ChunkedInput.readChunk.

Returns the next available HttpChunk.
public void
setBodyHttpDatas(List<InterfaceHttpData> datas)

Set the Body HttpDatas list

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait