Documentation of 'edu.rit.http.HttpRequest' Java class
HttpRequest
edu.rit.http

Class HttpRequest



  • public class HttpRequest
    extends java.lang.Object
    Class HttpRequest encapsulates an HTTP request received from a web browser.

    HTTP/1.0 and HTTP/1.1 requests are supported. The obsolete HTTP/0.9 requests are not supported.

    This class provides methods for examining the request line and the headers. This class does not support reading the entity body if any.

    To receive an HTTP request message:

    1. Call the isValid() method.
       
    2. If isValid() returns false, send an HTTP response message indicating the error.
       
    3. If isValid() returns true, call the other methods to examine the contents of the HTTP request message, and send an appropriate HTTP response message.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String GET_METHOD
      The GET method string, "GET".
      static java.lang.String HEAD_METHOD
      The HEAD method string, "HEAD".
      static java.lang.String HTTP_1_0_VERSION
      The HTTP/1.0 version string "HTTP/1.0".
      static java.lang.String HTTP_1_1_VERSION
      The HTTP/1.1 version string, "HTTP/1.1".
      static java.lang.String POST_METHOD
      The POST method string, "POST".
    • Constructor Summary

      Constructors 
      Constructor and Description
      HttpRequest(java.net.Socket theSocket)
      Construct a new HTTP request.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.String getHeader(java.lang.String theHeaderName)
      Obtain the value of the given header in this HTTP request.
      java.util.Collection<java.util.Map.Entry<java.lang.String,java.lang.String>> getHeaders()
      Obtain a collection of all the headers in this HTTP request.
      java.lang.String getHttpVersion()
      Obtain this HTTP request's version.
      java.lang.String getMethod()
      Obtain this HTTP request's method.
      java.lang.String getUri()
      Obtain this HTTP request's URI.
      boolean isValid()
      Determine if this HTTP request is valid.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • GET_METHOD

        public static final java.lang.String GET_METHOD
        The GET method string, "GET".
        See Also:
        Constant Field Values
      • HEAD_METHOD

        public static final java.lang.String HEAD_METHOD
        The HEAD method string, "HEAD".
        See Also:
        Constant Field Values
      • POST_METHOD

        public static final java.lang.String POST_METHOD
        The POST method string, "POST".
        See Also:
        Constant Field Values
      • HTTP_1_0_VERSION

        public static final java.lang.String HTTP_1_0_VERSION
        The HTTP/1.0 version string "HTTP/1.0".
        See Also:
        Constant Field Values
      • HTTP_1_1_VERSION

        public static final java.lang.String HTTP_1_1_VERSION
        The HTTP/1.1 version string, "HTTP/1.1".
        See Also:
        Constant Field Values
    • Constructor Detail

      • HttpRequest

        public HttpRequest(java.net.Socket theSocket)
        Construct a new HTTP request. The request is read from the input stream of the given socket.
        Parameters:
        theSocket - Socket.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theSocket is null.
    • Method Detail

      • isValid

        public boolean isValid()
        Determine if this HTTP request is valid. If the data read from the input stream of the socket given to the constructor represents a valid HTTP request message, true is returned, otherwise false is returned. If an I/O exception is thrown while reading the input, this HTTP request is marked as invalid, but the I/O exception is not propagated to the caller.
        Returns:
        True if this HTTP request is valid, false otherwise.
      • getMethod

        public java.lang.String getMethod()
        Obtain this HTTP request's method.
        Returns:
        Method string, e.g. "GET", "POST".
        Throws:
        java.lang.IllegalStateException - (unchecked exception) Thrown if this HTTP request is invalid.
      • getUri

        public java.lang.String getUri()
        Obtain this HTTP request's URI.
        Returns:
        URI string.
        Throws:
        java.lang.IllegalStateException - (unchecked exception) Thrown if this HTTP request is invalid.
      • getHttpVersion

        public java.lang.String getHttpVersion()
        Obtain this HTTP request's version.
        Returns:
        HTTP version string, e.g. "HTTP/1.0", "HTTP/1.1".
        Throws:
        java.lang.IllegalStateException - (unchecked exception) Thrown if this HTTP request is invalid.
      • getHeader

        public java.lang.String getHeader(java.lang.String theHeaderName)
        Obtain the value of the given header in this HTTP request.
        Parameters:
        theHeaderName - Header name.
        Returns:
        Header value, or null if there is no header for theHeaderName.
        Throws:
        java.lang.IllegalStateException - (unchecked exception) Thrown if this HTTP request is invalid.
      • getHeaders

        public java.util.Collection<java.util.Map.Entry<java.lang.String,java.lang.String>> getHeaders()
        Obtain a collection of all the headers in this HTTP request. The returned object is an unmodifiable collection of zero or more map entries. Each map entry's key is the header name. Each map entry's value is the corresponding header value.
        Returns:
        Unmodifiable collection of header name-value mappings.
        Throws:
        java.lang.IllegalStateException - (unchecked exception) Thrown if this HTTP request is invalid.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.