Package net.bjmsw.hda.vs.helper
Class BodyParser
java.lang.Object
net.bjmsw.hda.vs.helper.BodyParser
BodyParser class provides methods to parse different types of request bodies.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FormDataparseMultiPartFormData(String body, String boundary) Parses a multipart/form-data request bodystatic FormDataparseMultiPartFormDataNewLogic(byte[] bytes, int bodyStart) Implements the new logic for parsing multipart/form-datastatic FormDataParses URL-encoded form data from a given string.
-
Constructor Details
-
BodyParser
public BodyParser()
-
-
Method Details
-
parseXWwwFormUrlencoded
Parses URL-encoded form data from a given string.- Parameters:
body- the URL-encoded form data string- Returns:
- the parsed form data object as
FormData
-
parseMultiPartFormData
Parses a multipart/form-data request bodyThis approach is flawed and will not work for all requests Specifically, it will not work for requests containing binary files Since it uses Strings to parse the body, it will not be able to parse binary files
This is the original implementation of the method it is kept here for reference and is superseded by
parseMultiPartFormDataNewLogic(byte[], int)- Parameters:
body- the body of the requestboundary- the boundary string- Returns:
- the parsed
FormData
-
parseMultiPartFormDataNewLogic
Implements the new logic for parsing multipart/form-dataCan parse all multipart/form-data requests including files Files will be saved as a
FormDataFilein theFormData's file map- Parameters:
bytes- the byte array of the request bodybodyStart- the index of the first byte of the body- Returns:
- the parsed
FormData
-