Class DefaultHttpResponse

  • All Implemented Interfaces:
    HttpMessage, HttpResponse

    public class DefaultHttpResponse
    extends java.lang.Object
    implements HttpResponse
    The default implementation for the HTTP response element.
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultHttpResponse​(HttpVersion version, HttpStatus status, java.util.Map<java.lang.String,​java.lang.String> headers)
      Creates a new DefaultHttpResponse instance
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsHeader​(java.lang.String name)
      Tells if the message contains some header
      java.lang.String getContentType()
      Gets the Content-Type header of the message.
      java.lang.String getHeader​(java.lang.String name)
      Returns the value of the HTTP header with the specified name.
      java.util.Map<java.lang.String,​java.lang.String> getHeaders()
      HttpVersion getProtocolVersion()
      The HTTP version of the message
      HttpStatus getStatus()
      The HTTP status code for the HTTP response (e.g.
      boolean isKeepAlive()
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • headers

        private final java.util.Map<java.lang.String,​java.lang.String> headers
    • Constructor Detail

      • DefaultHttpResponse

        public DefaultHttpResponse​(HttpVersion version,
                                   HttpStatus status,
                                   java.util.Map<java.lang.String,​java.lang.String> headers)
        Creates a new DefaultHttpResponse instance
        Parameters:
        version - The HTTP version
        status - The HTTP status
        headers - The HTTP headers
    • Method Detail

      • getContentType

        public java.lang.String getContentType()
        Gets the Content-Type header of the message.
        Specified by:
        getContentType in interface HttpMessage
        Returns:
        The content type.
      • isKeepAlive

        public boolean isKeepAlive()
        Specified by:
        isKeepAlive in interface HttpMessage
        Returns:
        true if this message enables keep-alive connection.
      • getHeader

        public java.lang.String getHeader​(java.lang.String name)
        Returns the value of the HTTP header with the specified name. If more than one header with the given name is associated with this request, one is selected and returned.
        Specified by:
        getHeader in interface HttpMessage
        Parameters:
        name - The name of the desired header
        Returns:
        The header value - or null if no header is found with the specified name
      • containsHeader

        public boolean containsHeader​(java.lang.String name)
        Tells if the message contains some header
        Specified by:
        containsHeader in interface HttpMessage
        Parameters:
        name - the Header's name we are looking for
        Returns:
        true if the HTTP header with the specified name exists in this request.
      • getHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getHeaders()
        Specified by:
        getHeaders in interface HttpMessage
        Returns:
        a read-only Map of HTTP headers whose key is a String and whose value is a String s.
      • getStatus

        public HttpStatus getStatus()
        The HTTP status code for the HTTP response (e.g. 200 for OK, 404 for not found, etc..)
        Specified by:
        getStatus in interface HttpResponse
        Returns:
        the status of the HTTP response
      • toString

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