Class HttpPostRequestDecoder
java.lang.Object
io.netty.handler.codec.http.multipart.HttpPostRequestDecoder
- All Implemented Interfaces:
InterfaceHttpPostRequestDecoder
This decoder will decode Body and can handle POST BODY.
You MUST call
destroy() after completion to release all resources.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException when the body is fully decoded, even if there is still datastatic classException when an error occurs while decodingprotected static enumstates follow NOTSTARTED PREAMBLE ( (HEADERDELIMITER DISPOSITION (FIELD | FILEUPLOAD))* (HEADERDELIMITER DISPOSITION MIXEDPREAMBLE (MIXEDDELIMITER MIXEDDISPOSITION MIXEDFILEUPLOAD)+ MIXEDCLOSEDELIMITER)* CLOSEDELIMITER)+ EPILOGUE First getStatus is: NOSTARTED Content-type: multipart/form-data, boundary=AaB03x => PREAMBLE in Header --AaB03x => HEADERDELIMITER content-disposition: form-data; name="field1" => DISPOSITION Joe Blow => FIELD --AaB03x => HEADERDELIMITER content-disposition: form-data; name="pics" => DISPOSITION Content-type: multipart/mixed, boundary=BbC04y --BbC04y => MIXEDDELIMITER Content-disposition: attachment; filename="file1.txt" => MIXEDDISPOSITION Content-Type: text/plain ... contents of file1.txt ... => MIXEDFILEUPLOAD --BbC04y => MIXEDDELIMITER Content-disposition: file; filename="file2.gif" => MIXEDDISPOSITION Content-type: image/gif Content-Transfer-Encoding: binary ...contents of file2.gif... => MIXEDFILEUPLOAD --BbC04y-- => MIXEDCLOSEDELIMITER --AaB03x-- => CLOSEDELIMITER Once CLOSEDELIMITER is found, last getStatus is EPILOGUEstatic classException when try reading data from request in chunked format, and not enough data are available (need more chunks) -
Constructor Summary
ConstructorsConstructorDescriptionHttpPostRequestDecoder(HttpRequest request) HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request) HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset) -
Method Summary
Modifier and TypeMethodDescriptionvoidClean all HttpDatas (on Disk) for the current request.Returns the current InterfaceHttpData if currently in decoding status, meaning all data are not yet within, or null if there is no InterfaceHttpData currently in decoding status (either because none yet decoded or none currently partially decoded).voiddestroy()Destroy theInterfaceHttpPostRequestDecoderand release all it resources.getBodyHttpData(String name) This getMethod returns the first InterfaceHttpData with the given name from body.
If chunked, all chunks must have been offered using offer() getMethod.This getMethod returns a List of all HttpDatas from body.
If chunked, all chunks must have been offered using offer() getMethod.getBodyHttpDatas(String name) This getMethod returns a List of all HttpDatas with the given name from body.
If chunked, all chunks must have been offered using offer() getMethod.intReturn the threshold in bytes after which read data in the buffer should be discarded.protected static String[]getMultipartDataBoundary(String contentType) Check from the request ContentType if this request is a Multipart request.booleanhasNext()True if at current getStatus, there is an available decoded InterfaceHttpData from the Body.booleanTrue if this request is a Multipart requeststatic booleanisMultipart(HttpRequest request) Check if the given request is a multipart requestnext()Returns the next available InterfaceHttpData or null if, at the time it is called, there is no more available InterfaceHttpData.offer(HttpContent content) Initialized the internals from a new chunkvoidRemove the given FileUpload from the list of FileUploads to cleanvoidsetDiscardThreshold(int discardThreshold) Set the amount of bytes after which read bytes in the buffer should be discarded.
-
Constructor Details
-
HttpPostRequestDecoder
- Parameters:
request- the request to decode- Throws:
NullPointerException- for requestHttpPostRequestDecoder.ErrorDataDecoderException- if the default charset was wrong when decoding or other errors
-
HttpPostRequestDecoder
- Parameters:
factory- the factory used to create InterfaceHttpDatarequest- the request to decode- Throws:
NullPointerException- for request or factoryHttpPostRequestDecoder.ErrorDataDecoderException- if the default charset was wrong when decoding or other errors
-
HttpPostRequestDecoder
- Parameters:
factory- the factory used to create InterfaceHttpDatarequest- the request to decodecharset- the charset to use as default- Throws:
NullPointerException- for request or charset or factoryHttpPostRequestDecoder.ErrorDataDecoderException- if the default charset was wrong when decoding or other errors
-
-
Method Details
-
isMultipart
Check if the given request is a multipart request- Returns:
- True if the request is a Multipart request
-
getMultipartDataBoundary
Check from the request ContentType if this request is a Multipart request.- Returns:
- an array of String if multipartDataBoundary exists with the multipartDataBoundary as first element, charset if any as second (missing if not set), else null
-
isMultipart
public boolean isMultipart()Description copied from interface:InterfaceHttpPostRequestDecoderTrue if this request is a Multipart request- Specified by:
isMultipartin interfaceInterfaceHttpPostRequestDecoder- Returns:
- True if this request is a Multipart request
-
setDiscardThreshold
public void setDiscardThreshold(int discardThreshold) Description copied from interface:InterfaceHttpPostRequestDecoderSet the amount of bytes after which read bytes in the buffer should be discarded. Setting this lower gives lower memory usage but with the overhead of more memory copies. Use0to disable it.- Specified by:
setDiscardThresholdin interfaceInterfaceHttpPostRequestDecoder
-
getDiscardThreshold
public int getDiscardThreshold()Description copied from interface:InterfaceHttpPostRequestDecoderReturn the threshold in bytes after which read data in the buffer should be discarded.- Specified by:
getDiscardThresholdin interfaceInterfaceHttpPostRequestDecoder
-
getBodyHttpDatas
Description copied from interface:InterfaceHttpPostRequestDecoderThis getMethod returns a List of all HttpDatas from body.
If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.- Specified by:
getBodyHttpDatasin interfaceInterfaceHttpPostRequestDecoder- Returns:
- the list of HttpDatas from Body part for POST getMethod
-
getBodyHttpDatas
Description copied from interface:InterfaceHttpPostRequestDecoderThis getMethod returns a List of all HttpDatas with the given name from body.
If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.- Specified by:
getBodyHttpDatasin interfaceInterfaceHttpPostRequestDecoder- Returns:
- All Body HttpDatas with the given name (ignore case)
-
getBodyHttpData
Description copied from interface:InterfaceHttpPostRequestDecoderThis getMethod returns the first InterfaceHttpData with the given name from body.
If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.- Specified by:
getBodyHttpDatain interfaceInterfaceHttpPostRequestDecoder- Returns:
- The first Body InterfaceHttpData with the given name (ignore case)
-
offer
Description copied from interface:InterfaceHttpPostRequestDecoderInitialized the internals from a new chunk- Specified by:
offerin interfaceInterfaceHttpPostRequestDecoder- Parameters:
content- the new received chunk
-
hasNext
public boolean hasNext()Description copied from interface:InterfaceHttpPostRequestDecoderTrue if at current getStatus, there is an available decoded InterfaceHttpData from the Body. This getMethod works for chunked and not chunked request.- Specified by:
hasNextin interfaceInterfaceHttpPostRequestDecoder- Returns:
- True if at current getStatus, there is a decoded InterfaceHttpData
-
next
Description copied from interface:InterfaceHttpPostRequestDecoderReturns the next available InterfaceHttpData or null if, at the time it is called, there is no more available InterfaceHttpData. A subsequent call to offer(httpChunk) could enable more data. Be sure to callReferenceCounted.release()after you are done with processing to make sure to not leak any resources- Specified by:
nextin interfaceInterfaceHttpPostRequestDecoder- Returns:
- the next available InterfaceHttpData or null if none
-
currentPartialHttpData
Description copied from interface:InterfaceHttpPostRequestDecoderReturns the current InterfaceHttpData if currently in decoding status, meaning all data are not yet within, or null if there is no InterfaceHttpData currently in decoding status (either because none yet decoded or none currently partially decoded). Full decoded ones are accessible through hasNext() and next() methods.- Specified by:
currentPartialHttpDatain interfaceInterfaceHttpPostRequestDecoder- Returns:
- the current InterfaceHttpData if currently in decoding status or null if none.
-
destroy
public void destroy()Description copied from interface:InterfaceHttpPostRequestDecoderDestroy theInterfaceHttpPostRequestDecoderand release all it resources. After this method was called it is not possible to operate on it anymore.- Specified by:
destroyin interfaceInterfaceHttpPostRequestDecoder
-
cleanFiles
public void cleanFiles()Description copied from interface:InterfaceHttpPostRequestDecoderClean all HttpDatas (on Disk) for the current request.- Specified by:
cleanFilesin interfaceInterfaceHttpPostRequestDecoder
-
removeHttpDataFromClean
Description copied from interface:InterfaceHttpPostRequestDecoderRemove the given FileUpload from the list of FileUploads to clean- Specified by:
removeHttpDataFromCleanin interfaceInterfaceHttpPostRequestDecoder
-