Package org.omegazero.http.h1
Class HTTP1Util
java.lang.Object
org.omegazero.http.h1.HTTP1Util
HTTP/1 utility functions.
- Since:
- 1.2.1
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic HTTPRequestDataparseHTTPRequest(byte[] data, int offset, boolean secure) Parses a complete HTTP request header block using aHTTP1RequestReceiverfrom the given data, starting at offset.static HTTPResponseDataparseHTTPResponse(byte[] data, int offset) Parses a complete HTTP response header block using aHTTP1ResponseReceiverfrom the given data, starting at offset.static byte[]toChunk(byte[] data) Wraps the given data in a HTTP/1 data chunk used in chunked transfer encoding.
-
Field Details
-
EOL_STR
- See Also:
-
-
Method Details
-
toChunk
public static byte[] toChunk(byte[] data) Wraps the given data in a HTTP/1 data chunk used in chunked transfer encoding.The resulting byte array has this format:
<length of data as hexadecimal number>\r\n <given data>\r\n- Parameters:
data- The data to wrap- Returns:
- The data as a chunk
-
parseHTTPRequest
public static HTTPRequestData parseHTTPRequest(byte[] data, int offset, boolean secure) throws InvalidHTTPMessageException Parses a complete HTTP request header block using aHTTP1RequestReceiverfrom the given data, starting at offset.- Parameters:
data- The dataoffset- The index to start reading atsecure- SeeHTTP1RequestReceiver(boolean)- Returns:
- A
HTTPRequestDatacontaining the HTTP header and any trailing body data - Throws:
InvalidHTTPMessageException- If the given data contains an invalid or incomplete HTTP request header
-
parseHTTPResponse
public static HTTPResponseData parseHTTPResponse(byte[] data, int offset) throws InvalidHTTPMessageException Parses a complete HTTP response header block using aHTTP1ResponseReceiverfrom the given data, starting at offset.- Parameters:
data- The dataoffset- The index to start reading at- Returns:
- A
HTTPResponseDatacontaining the HTTP header and any trailing body data - Throws:
InvalidHTTPMessageException- If the given data contains an invalid or incomplete HTTP response header
-