Class HttpServer.Request

  • Enclosing class:
    HttpServer

    public static class HttpServer.Request
    extends java.lang.Object
    Represents a parsed HTTP client request.
    • Constructor Summary

      Constructors 
      Constructor Description
      Request​(java.lang.String method, java.lang.String url, java.util.Map headerMap, java.net.SocketAddress remoteAddress, byte[] body)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] getBody()
      Returns the body of the HTTP request if there was one.
      java.util.Map getHeaderMap()
      Returns a map of key-value pairs representing HTTP request headers.
      java.lang.String getMethod()
      Returns the request method string.
      java.net.SocketAddress getRemoteAddress()
      Returns the address of the client which made this request.
      java.lang.String getUrl()
      Returns the request URL string.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Request

        public Request​(java.lang.String method,
                       java.lang.String url,
                       java.util.Map headerMap,
                       java.net.SocketAddress remoteAddress,
                       byte[] body)
        Constructor.
        Parameters:
        method - HTTP method string (GET, HEAD etc)
        url - requested URL path (should start "/")
        headerMap - map of HTTP request header key-value pairs
        remoteAddress - address of the client making the request
        body - bytes comprising request body, or null if none present
    • Method Detail

      • getMethod

        public java.lang.String getMethod()
        Returns the request method string.
        Returns:
        GET, HEAD, or whatever
      • getUrl

        public java.lang.String getUrl()
        Returns the request URL string. This should be a path starting "/" (the hostname part is not present).
        Returns:
        url path
      • getHeaderMap

        public java.util.Map getHeaderMap()
        Returns a map of key-value pairs representing HTTP request headers. Note that for HTTP usage, header keys are case-insensitive (RFC2616 sec 4.2); the HttpServer.getHeader(java.util.Map, java.lang.String) utility method can be used to interrogate the returned map.
        Returns:
        header map
      • getRemoteAddress

        public java.net.SocketAddress getRemoteAddress()
        Returns the address of the client which made this request.
        Returns:
        requesting client's socket address
      • getBody

        public byte[] getBody()
        Returns the body of the HTTP request if there was one.
        Returns:
        body bytes or null
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object