Class HttpHeaders
- java.lang.Object
-
- com.okta.commons.http.HttpHeaders
-
- All Implemented Interfaces:
java.util.Map<java.lang.String,java.util.List<java.lang.String>>
public class HttpHeaders extends java.lang.Object- Since:
- 0.5.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringLINKstatic java.lang.StringOKTA_AGENTstatic java.lang.StringOKTA_CLIENT_REQUEST_IDstatic java.lang.StringOKTA_REQUEST_IDstatic java.lang.StringOKTA_USER_AGENTstatic java.lang.StringUSER_AGENT
-
Constructor Summary
Constructors Constructor Description HttpHeaders()Constructs a new, empty instance of theHttpHeadersobject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.String headerName, java.lang.String headerValue)Add the given, single header value under the given name.voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>>entrySet()booleanequals(java.lang.Object other)java.util.List<java.lang.String>get(java.lang.Object key)java.util.List<MediaType>getAccept()Return the list of acceptable media types, as specified by theAcceptheader.java.util.List<java.nio.charset.Charset>getAcceptCharset()Return the list of acceptable charsets, as specified by theAccept-Charsetheader.java.util.Set<HttpMethod>getAllow()Return the set of allowedHTTP methods, as specified by theAllowheader.java.lang.StringgetCacheControl()Returns the value of theCache-Controlheader.longgetContentLength()Return the length of the body in bytes, as specified by theContent-Lengthheader.MediaTypegetContentType()Return the media type of the body, as specified by theContent-Typeheader.longgetDate()Returns the date and time at which the message was created, as specified by theDateheader.java.lang.StringgetETag()Returns the entity tag of the body, as specified by theETagheader.longgetExpires()Returns the date and time at which the message is no longer valid, as specified by theExpiresheader.java.lang.StringgetFirst(java.lang.String headerName)Return the first header value for the given header name, if any.java.util.List<java.lang.String>getIfNoneMatch()Returns the value of theIf-None-Matchheader.longgetIfNotModifiedSince()Returns the value of theIfModifiedSinceheader.longgetLastModified()Returns the time the resource was last changed, as specified by theLast-Modifiedheader.java.util.List<java.lang.String>getLinkHeaders()java.util.Map<java.lang.String,java.lang.String>getLinkMap()java.net.URIgetLocation()Return the (new) location of a resource, as specified by theLocationheader.java.lang.StringgetOktaRequestId()Returns the value of theOkta-Request-Idheader.java.lang.StringgetPragma()Returns the value of thePragmaheader.java.util.Map<java.lang.String,java.util.List<java.lang.String>>getXHeaders()inthashCode()booleanisEmpty()java.util.Set<java.lang.String>keySet()java.util.List<java.lang.String>put(java.lang.String key, java.util.List<java.lang.String> value)voidputAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> m)static HttpHeadersreadOnlyHttpHeaders(HttpHeaders headers)ReturnsHttpHeadersobject that can only be read, not written to.java.util.List<java.lang.String>remove(java.lang.Object key)voidset(java.lang.String headerName, java.lang.String headerValue)Set the given, single header value under the given name.voidsetAccept(java.util.List<MediaType> acceptableMediaTypes)Set the list of acceptable media types, as specified by theAcceptheader.voidsetAcceptCharset(java.util.List<java.nio.charset.Charset> acceptableCharsets)Set the list of acceptable charsets, as specified by theAccept-Charsetheader.voidsetAll(java.util.Map<java.lang.String,java.lang.String> values)voidsetAllow(java.util.Set<HttpMethod> allowedMethods)Set the set of allowedHTTP methods, as specified by theAllowheader.voidsetCacheControl(java.lang.String cacheControl)Sets the (new) value of theCache-Controlheader.voidsetContentDispositionFormData(java.lang.String name, java.lang.String filename)Sets the (new) value of theContent-Dispositionheader forform-data.voidsetContentLength(long contentLength)Set the length of the body in bytes, as specified by theContent-Lengthheader.voidsetContentType(MediaType mediaType)Set the media type of the body, as specified by theContent-Typeheader.voidsetDate(long date)Sets the date and time at which the message was created, as specified by theDateheader.voidsetETag(java.lang.String eTag)Sets the (new) entity tag of the body, as specified by theETagheader.voidsetExpires(long expires)Sets the date and time at which the message is no longer valid, as specified by theExpiresheader.voidsetIfModifiedSince(long ifModifiedSince)Sets the (new) value of theIf-Modified-Sinceheader.voidsetIfNoneMatch(java.lang.String ifNoneMatch)Sets the (new) value of theIf-None-Matchheader.voidsetIfNoneMatch(java.util.List<java.lang.String> ifNoneMatchList)Sets the (new) values of theIf-None-Matchheader.voidsetLastModified(long lastModified)Sets the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetLocation(java.net.URI location)Set the (new) location of a resource, as specified by theLocationheader.voidsetPragma(java.lang.String pragma)Sets the (new) value of thePragmaheader.intsize()java.util.Map<java.lang.String,java.lang.String>toSingleValueMap()java.lang.StringtoString()java.util.Collection<java.util.List<java.lang.String>>values()
-
-
-
Field Detail
-
LINK
public static final java.lang.String LINK
- See Also:
- Constant Field Values
-
OKTA_REQUEST_ID
public static final java.lang.String OKTA_REQUEST_ID
- See Also:
- Constant Field Values
-
OKTA_AGENT
public static final java.lang.String OKTA_AGENT
- See Also:
- Constant Field Values
-
OKTA_CLIENT_REQUEST_ID
public static final java.lang.String OKTA_CLIENT_REQUEST_ID
- See Also:
- Constant Field Values
-
OKTA_USER_AGENT
public static final java.lang.String OKTA_USER_AGENT
- See Also:
- Constant Field Values
-
USER_AGENT
public static final java.lang.String USER_AGENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
readOnlyHttpHeaders
public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
ReturnsHttpHeadersobject that can only be read, not written to.- Parameters:
headers- source headers- Returns:
- readonly copy of the source
headers
-
setAccept
public void setAccept(java.util.List<MediaType> acceptableMediaTypes)
Set the list of acceptable media types, as specified by theAcceptheader.- Parameters:
acceptableMediaTypes- the acceptable media types
-
getAccept
public java.util.List<MediaType> getAccept()
Return the list of acceptable media types, as specified by theAcceptheader.Returns an empty list when the acceptable media types are unspecified.
- Returns:
- the acceptable media types
-
setAcceptCharset
public void setAcceptCharset(java.util.List<java.nio.charset.Charset> acceptableCharsets)
Set the list of acceptable charsets, as specified by theAccept-Charsetheader.- Parameters:
acceptableCharsets- the acceptable charsets
-
getAcceptCharset
public java.util.List<java.nio.charset.Charset> getAcceptCharset()
Return the list of acceptable charsets, as specified by theAccept-Charsetheader.- Returns:
- the acceptable charsets
-
setAllow
public void setAllow(java.util.Set<HttpMethod> allowedMethods)
Set the set of allowedHTTP methods, as specified by theAllowheader.- Parameters:
allowedMethods- the allowed methods
-
getAllow
public java.util.Set<HttpMethod> getAllow()
Return the set of allowedHTTP methods, as specified by theAllowheader.Returns an empty set when the allowed methods are unspecified.
- Returns:
- the allowed methods
-
setCacheControl
public void setCacheControl(java.lang.String cacheControl)
Sets the (new) value of theCache-Controlheader.- Parameters:
cacheControl- the value of the header
-
getCacheControl
public java.lang.String getCacheControl()
Returns the value of theCache-Controlheader.- Returns:
- the value of the header
-
setContentDispositionFormData
public void setContentDispositionFormData(java.lang.String name, java.lang.String filename)Sets the (new) value of theContent-Dispositionheader forform-data.- Parameters:
name- the control namefilename- the filename, may benull
-
setContentLength
public void setContentLength(long contentLength)
Set the length of the body in bytes, as specified by theContent-Lengthheader. IfcontentLengthis negative, theContent-Lengthheader 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 theContent-Lengthheader.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 theContent-Typeheader.- Parameters:
mediaType- the media type
-
getContentType
public MediaType getContentType()
Return the media type of the body, as specified by theContent-Typeheader.Returns
nullwhen 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 theDateheader.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 theDateheader.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:
java.lang.IllegalArgumentException- if the value can't be converted to a date
-
setETag
public void setETag(java.lang.String eTag)
Sets the (new) entity tag of the body, as specified by theETagheader.- Parameters:
eTag- the new entity tag
-
getETag
public java.lang.String getETag()
Returns the entity tag of the body, as specified by theETagheader.- 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 theExpiresheader.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 theExpiresheader.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 theIf-Modified-Sinceheader.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 theIfModifiedSinceheader.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(java.lang.String ifNoneMatch)
Sets the (new) value of theIf-None-Matchheader.- Parameters:
ifNoneMatch- the new value of the header
-
setIfNoneMatch
public void setIfNoneMatch(java.util.List<java.lang.String> ifNoneMatchList)
Sets the (new) values of theIf-None-Matchheader.- Parameters:
ifNoneMatchList- the new value of the header
-
getIfNoneMatch
public java.util.List<java.lang.String> getIfNoneMatch()
Returns the value of theIf-None-Matchheader.- Returns:
- the header value
-
setLastModified
public void setLastModified(long lastModified)
Sets the time the resource was last changed, as specified by theLast-Modifiedheader.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 theLast-Modifiedheader.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(java.net.URI location)
Set the (new) location of a resource, as specified by theLocationheader.- Parameters:
location- the location
-
getLocation
public java.net.URI getLocation()
Return the (new) location of a resource, as specified by theLocationheader.Returns
nullwhen the location is unknown.- Returns:
- the location
-
setPragma
public void setPragma(java.lang.String pragma)
Sets the (new) value of thePragmaheader.- Parameters:
pragma- the value of the header
-
getPragma
public java.lang.String getPragma()
Returns the value of thePragmaheader.- Returns:
- the value of the header
-
getOktaRequestId
public java.lang.String getOktaRequestId()
Returns the value of theOkta-Request-Idheader.- Returns:
- the value of the header
-
getLinkHeaders
public java.util.List<java.lang.String> getLinkHeaders()
-
getLinkMap
public java.util.Map<java.lang.String,java.lang.String> getLinkMap()
-
getFirst
public java.lang.String getFirst(java.lang.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(java.lang.String headerName, java.lang.String headerValue)Add the given, single header value under the given name.- Parameters:
headerName- the header nameheaderValue- the header value- Throws:
java.lang.UnsupportedOperationException- if adding headers is not supported- See Also:
put(String, List),set(String, String)
-
set
public void set(java.lang.String headerName, java.lang.String headerValue)Set the given, single header value under the given name.- Parameters:
headerName- the header nameheaderValue- the header value- Throws:
java.lang.UnsupportedOperationException- if adding headers is not supported- See Also:
put(String, List),add(String, String)
-
setAll
public void setAll(java.util.Map<java.lang.String,java.lang.String> values)
-
toSingleValueMap
public java.util.Map<java.lang.String,java.lang.String> toSingleValueMap()
-
getXHeaders
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getXHeaders()
-
size
public int size()
- Specified by:
sizein interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKeyin interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValuein interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
get
public java.util.List<java.lang.String> get(java.lang.Object key)
- Specified by:
getin interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
put
public java.util.List<java.lang.String> put(java.lang.String key, java.util.List<java.lang.String> value)- Specified by:
putin interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
remove
public java.util.List<java.lang.String> remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
putAll
public void putAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> m)
- Specified by:
putAllin interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
keySet
public java.util.Set<java.lang.String> keySet()
- Specified by:
keySetin interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
values
public java.util.Collection<java.util.List<java.lang.String>> values()
- Specified by:
valuesin interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> entrySet()
- Specified by:
entrySetin interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>
-
equals
public boolean equals(java.lang.Object other)
- Specified by:
equalsin interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Map<java.lang.String,java.util.List<java.lang.String>>- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-