Class HttpHeaders

java.lang.Object
com.okta.commons.http.HttpHeaders
All Implemented Interfaces:
Map<String,List<String>>

public class HttpHeaders extends Object
Since:
0.5.0
  • Field Details

  • Constructor Details

    • HttpHeaders

      public HttpHeaders()
      Constructs a new, empty instance of the HttpHeaders object.
  • Method Details

    • readOnlyHttpHeaders

      public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
      Returns HttpHeaders object that can only be read, not written to.
      Parameters:
      headers - source headers
      Returns:
      readonly copy of the source headers
    • setAccept

      public void setAccept(List<MediaType> acceptableMediaTypes)
      Set the list of acceptable media types, as specified by the Accept header.
      Parameters:
      acceptableMediaTypes - the acceptable media types
    • getAccept

      public List<MediaType> getAccept()
      Return the list of acceptable media types, as specified by the Accept header.

      Returns an empty list when the acceptable media types are unspecified.

      Returns:
      the acceptable media types
    • setAcceptCharset

      public void setAcceptCharset(List<Charset> acceptableCharsets)
      Set the list of acceptable charsets, as specified by the Accept-Charset header.
      Parameters:
      acceptableCharsets - the acceptable charsets
    • getAcceptCharset

      public List<Charset> getAcceptCharset()
      Return the list of acceptable charsets, as specified by the Accept-Charset header.
      Returns:
      the acceptable charsets
    • setAllow

      public void setAllow(Set<HttpMethod> allowedMethods)
      Set the set of allowed HTTP methods, as specified by the Allow header.
      Parameters:
      allowedMethods - the allowed methods
    • getAllow

      public Set<HttpMethod> getAllow()
      Return the set of allowed HTTP methods, as specified by the Allow header.

      Returns an empty set when the allowed methods are unspecified.

      Returns:
      the allowed methods
    • setCacheControl

      public void setCacheControl(String cacheControl)
      Sets the (new) value of the Cache-Control header.
      Parameters:
      cacheControl - the value of the header
    • getCacheControl

      public String getCacheControl()
      Returns the value of the Cache-Control header.
      Returns:
      the value of the header
    • setContentDispositionFormData

      public void setContentDispositionFormData(String name, String filename)
      Sets the (new) value of the Content-Disposition header for form-data.
      Parameters:
      name - the control name
      filename - the filename, may be null
    • setContentLength

      public void setContentLength(long contentLength)
      Set the length of the body in bytes, as specified by the Content-Length header. If contentLength is negative, the Content-Length header will be removed (not set).
      Parameters:
      contentLength - the content length
    • getContentLength

      public long getContentLength()
      Return the length of the body in bytes, as specified by the Content-Length header.

      Returns -1 when the content-length is unknown.

      Returns:
      the content length
    • setContentType

      public void setContentType(MediaType mediaType)
      Set the media type of the body, as specified by the Content-Type header.
      Parameters:
      mediaType - the media type
    • getContentType

      public MediaType getContentType()
      Return the media type of the body, as specified by the Content-Type header.

      Returns null when the content-type is unknown.

      Returns:
      the content type
    • setDate

      public void setDate(long date)
      Sets the date and time at which the message was created, as specified by the Date header.

      The date should be specified as the number of milliseconds since January 1, 1970 GMT.

      Parameters:
      date - the date
    • getDate

      public long getDate()
      Returns the date and time at which the message was created, as specified by the Date header.

      The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

      Returns:
      the creation date/time
      Throws:
      IllegalArgumentException - if the value can't be converted to a date
    • setETag

      public void setETag(String eTag)
      Sets the (new) entity tag of the body, as specified by the ETag header.
      Parameters:
      eTag - the new entity tag
    • getETag

      public String getETag()
      Returns the entity tag of the body, as specified by the ETag header.
      Returns:
      the entity tag
    • setExpires

      public void setExpires(long expires)
      Sets the date and time at which the message is no longer valid, as specified by the Expires header.

      The date should be specified as the number of milliseconds since January 1, 1970 GMT.

      Parameters:
      expires - the new expires header value
    • getExpires

      public long getExpires()
      Returns the date and time at which the message is no longer valid, as specified by the Expires header.

      The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

      Returns:
      the expires value
    • setIfModifiedSince

      public void setIfModifiedSince(long ifModifiedSince)
      Sets the (new) value of the If-Modified-Since header.

      The date should be specified as the number of milliseconds since January 1, 1970 GMT.

      Parameters:
      ifModifiedSince - the new value of the header
    • getIfNotModifiedSince

      public long getIfNotModifiedSince()
      Returns the value of the IfModifiedSince header.

      The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

      Returns:
      the header value
    • setIfNoneMatch

      public void setIfNoneMatch(String ifNoneMatch)
      Sets the (new) value of the If-None-Match header.
      Parameters:
      ifNoneMatch - the new value of the header
    • setIfNoneMatch

      public void setIfNoneMatch(List<String> ifNoneMatchList)
      Sets the (new) values of the If-None-Match header.
      Parameters:
      ifNoneMatchList - the new value of the header
    • getIfNoneMatch

      public List<String> getIfNoneMatch()
      Returns the value of the If-None-Match header.
      Returns:
      the header value
    • setLastModified

      public void setLastModified(long lastModified)
      Sets the time the resource was last changed, as specified by the Last-Modified header.

      The date should be specified as the number of milliseconds since January 1, 1970 GMT.

      Parameters:
      lastModified - the last modified date
    • getLastModified

      public long getLastModified()
      Returns the time the resource was last changed, as specified by the Last-Modified header.

      The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

      Returns:
      the last modified date
    • setLocation

      public void setLocation(URI location)
      Set the (new) location of a resource, as specified by the Location header.
      Parameters:
      location - the location
    • getLocation

      public URI getLocation()
      Return the (new) location of a resource, as specified by the Location header.

      Returns null when the location is unknown.

      Returns:
      the location
    • setPragma

      public void setPragma(String pragma)
      Sets the (new) value of the Pragma header.
      Parameters:
      pragma - the value of the header
    • getPragma

      public String getPragma()
      Returns the value of the Pragma header.
      Returns:
      the value of the header
    • getOktaRequestId

      public String getOktaRequestId()
      Returns the value of the Okta-Request-Id header.
      Returns:
      the value of the header
    • getLinkHeaders

      public List<String> getLinkHeaders()
    • getLinkMap

      public Map<String,String> getLinkMap()
    • getFirst

      public String getFirst(String headerName)
      Return the first header value for the given header name, if any.
      Parameters:
      headerName - the header name
      Returns:
      the first header value; or null
    • add

      public void add(String headerName, String headerValue)
      Add the given, single header value under the given name.
      Parameters:
      headerName - the header name
      headerValue - the header value
      Throws:
      UnsupportedOperationException - if adding headers is not supported
      See Also:
    • set

      public void set(String headerName, String headerValue)
      Set the given, single header value under the given name.
      Parameters:
      headerName - the header name
      headerValue - the header value
      Throws:
      UnsupportedOperationException - if adding headers is not supported
      See Also:
    • setAll

      public void setAll(Map<String,String> values)
    • toSingleValueMap

      public Map<String,String> toSingleValueMap()
    • getXHeaders

      public Map<String,List<String>> getXHeaders()
    • size

      public int size()
      Specified by:
      size in interface Map<String,List<String>>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<String,List<String>>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<String,List<String>>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<String,List<String>>
    • get

      public List<String> get(Object key)
      Specified by:
      get in interface Map<String,List<String>>
    • put

      public List<String> put(String key, List<String> value)
      Specified by:
      put in interface Map<String,List<String>>
    • remove

      public List<String> remove(Object key)
      Specified by:
      remove in interface Map<String,List<String>>
    • putAll

      public void putAll(Map<? extends String,? extends List<String>> m)
      Specified by:
      putAll in interface Map<String,List<String>>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<String,List<String>>
    • keySet

      public Set<String> keySet()
      Specified by:
      keySet in interface Map<String,List<String>>
    • values

      public Collection<List<String>> values()
      Specified by:
      values in interface Map<String,List<String>>
    • entrySet

      public Set<Map.Entry<String,List<String>>> entrySet()
      Specified by:
      entrySet in interface Map<String,List<String>>
    • equals

      public boolean equals(Object other)
      Specified by:
      equals in interface Map<String,List<String>>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<String,List<String>>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object