Package ej.hoka.http

Class HttpRequest


  • public class HttpRequest
    extends Object
    Represents a HTTP Request.
    • Constructor Detail

      • HttpRequest

        protected HttpRequest​(InputStream inputStream,
                              EncodingRegistry encodingRegistry)
                       throws IOException
        Constructs a new instance of HTTPRequest.
        Parameters:
        inputStream - the input stream of the request.
        encodingRegistry - the register of available encoding and transfer coding handlers.
        Throws:
        IOException - if connection is lost during processing the request.
        IllegalArgumentException - if parsing the request failed.
    • Method Detail

      • getMethod

        public int getMethod()
        Returns the request method as an integer value which is one of POST, GET, PUT or DELETE.
        Returns:
        the request method (one of POST, GET, PUT or DELETE).
      • getURI

        public String getURI()
        Returns the request URI.
        Returns:
        the request URI string.
      • getQueryParams

        public Map<String,​String> getQueryParams()
        Returns the Query parameters as Map.
        Returns:
        a Map of (String,String) representing the HTTP query parameters.
      • getQueryParam

        @Nullable
        public String getQueryParam​(String name)
        Returns the query parameter mapped to the given name.
        Parameters:
        name - of query parameter
        Returns:
        the parameter mapped to name
      • getPathParam

        @Nullable
        public String getPathParam​(String param)
        Returns the path parameter value mapped to the given name.
        Parameters:
        param - path parameter name
        Returns:
        path parameter value if exist, null otherwise
      • getSplatParams

        public List<String> getSplatParams()
        Returns the list of splat parameters.
        Returns:
        a List of splat parameters.
      • addSplatParameters

        protected void addSplatParameters​(List<String> splatParameters)
        Sets the splat Parameters.
        Parameters:
        splatParameters - the splat parameters to set.
      • addPathParameters

        protected void addPathParameters​(Map<String,​String> parameters)
        Adds path parameters from a given list to the list of path path parameters of the request.
        Parameters:
        parameters - path parameters to be added to the request
      • getAttribute

        @Nullable
        public Object getAttribute​(String key)
        Get request server-side attribute by key.
        Parameters:
        key - attribute key
        Returns:
        value mapped to key
      • setAttribute

        public void setAttribute​(String key,
                                 Object value)
        Set a request server-side attribute.
        Parameters:
        key - attribute key
        value - attribute value
      • getVersion

        public String getVersion()
        Returns the HTTP version request.
        Returns:
        the HTTP version request string.
      • getHeaders

        public Map<String,​String> getHeaders()
        Returns all HTTP header fields of the request.
        Returns:
        a Map of (String,String) representing the HTTP header fields (may be empty).
      • getHeader

        @Nullable
        public String getHeader​(@Nullable
                                String name)
        Returns the header field value associated to the given header field name.
        Parameters:
        name - the header field name.
        Returns:
        the requested header field value, null if the header field is not found or name is null.
      • getCookies

        public Map<String,​String> getCookies()
        Returns the cookies of the request.

        Cookies are lazily parsed.

        Returns:
        a Map of (String,String) representing the HTTP cookies (may be empty)
      • getCookie

        @Nullable
        public String getCookie​(@Nullable
                                String name)
        Return the cookie of the request with given name.

        Cookies are lazily parsed.

        Parameters:
        name - the name of the cookie.
        Returns:
        the cookie, or null if name is null.
      • parseBody

        public <T> T parseBody​(BodyParser<T> bodyParser)
                        throws IOException
        Request the body to be parsed.
        Type Parameters:
        T - the type of body.
        Parameters:
        bodyParser - the parser.
        Returns:
        the parsed body.
        Throws:
        IOException - if an IOException occurs during parsing.
      • getRequestBody

        public InputStream getRequestBody()
        use parseBody(BodyParser) for more option on request body provided parsers.
        Returns:
        request request body as an input stream.