Class BodyParser

java.lang.Object
net.bjmsw.hda.vs.helper.BodyParser

public class BodyParser extends Object
BodyParser class provides methods to parse different types of request bodies.
  • Constructor Details

    • BodyParser

      public BodyParser()
  • Method Details

    • parseXWwwFormUrlencoded

      public static FormData parseXWwwFormUrlencoded(String body)
      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

      public static FormData parseMultiPartFormData(String body, String boundary)
      Parses a multipart/form-data request body

      This 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 request
      boundary - the boundary string
      Returns:
      the parsed FormData
    • parseMultiPartFormDataNewLogic

      public static FormData parseMultiPartFormDataNewLogic(byte[] bytes, int bodyStart)
      Implements the new logic for parsing multipart/form-data

      Can parse all multipart/form-data requests including files Files will be saved as a FormDataFile in the FormData's file map

      Parameters:
      bytes - the byte array of the request body
      bodyStart - the index of the first byte of the body
      Returns:
      the parsed FormData