• April 20, 2024

Httpheaders

HttpHeaders (Spring Framework 5.3.10 API)

HttpHeaders (Spring Framework 5.3.10 API)

Modifier and Type
Method and Description
void
add(String headerName,
String headerValue)
Add the given, single header value under the given name.
addAll(MultiValueMap values)
Add all the values of the given MultiValueMap to the current values.
addAll(String key,
List values)
Add all the values of the given list to the current list of values for the given key.
clear()
clearContentHeaders()
Remove the well-known “Content-*” HTTP headers.
boolean
containsKey(Object key)
containsValue(Object value)
static String
encodeBasicAuth(String username,
String password,
Charset charset)
Encode the given username and password into Basic Authentication credentials.
Set<>>
entrySet()
equals(Object other)
formatHeaders(MultiValueMap headers)
Helps to format HTTP header values, as HTTP header values themselves can
contain comma-separated values, can become confusing with regular
Map formatting that also uses commas between entries.
List
get(Object key)
List
getAccept()
Return the list of acceptable media types,
as specified by the Accept header.
List
getAcceptCharset()
Return the list of acceptable charsets,
as specified by the Accept-Charset header.
List
getAcceptLanguage()
Return the language ranges from the “Accept-Language” header.
List
getAcceptLanguageAsLocales()
getAcceptPatch()
Return the list of acceptable media types for
PATCH methods, as specified by the Accept-Patch header.
getAccessControlAllowCredentials()
Return the value of the Access-Control-Allow-Credentials response header.
getAccessControlAllowHeaders()
Return the value of the Access-Control-Allow-Headers response header.
List
getAccessControlAllowMethods()
Return the value of the Access-Control-Allow-Methods response header.
String
getAccessControlAllowOrigin()
Return the value of the Access-Control-Allow-Origin response header.
getAccessControlExposeHeaders()
Return the value of the Access-Control-Expose-Headers response header.
long
getAccessControlMaxAge()
Return the value of the Access-Control-Max-Age response header.
getAccessControlRequestHeaders()
Return the value of the Access-Control-Request-Headers request header.
HttpMethod
getAccessControlRequestMethod()
Return the value of the Access-Control-Request-Method request header.
Set
getAllow()
Return the set of allowed HTTP methods,
as specified by the Allow header.
getCacheControl()
Return the value of the Cache-Control header.
getConnection()
Return the value of the Connection header.
ContentDisposition
getContentDisposition()
Return a parsed representation of the Content-Disposition header.
Locale
getContentLanguage()
Get the first Locale of the content languages, as specified by the
Content-Language header.
getContentLength()
Return the length of the body in bytes, as specified by the
Content-Length header.
MediaType
getContentType()
Return the media type of the body, as specified
by the Content-Type header.
getDate()
Return the date and time at which the message was created, as specified
by the Date header.
getETag()
Return the entity tag of the body, as specified by the ETag header.
protected List
getETagValuesAsList(String headerName)
Retrieve a combined result from the field values of the ETag header.
getExpires()
Return the date and time at which the message is no longer valid,
as specified by the Expires header.
protected String
getFieldValues(String headerName)
Retrieve a combined result from the field values of multi-valued headers.
getFirst(String headerName)
Return the first header value for the given header name, if any.
getFirstDate(String headerName)
Parse the first header value for the given header name as a date,
return -1 if there is no value, or raise IllegalArgumentException
if the value cannot be parsed as a date.
ZonedDateTime
getFirstZonedDateTime(String headerName)
return null if there is no value, or raise IllegalArgumentException
InetSocketAddress
getHost()
Return the value of the Host header, if available.
getIfMatch()
Return the value of the If-Match header.
getIfModifiedSince()
Return the value of the If-Modified-Since header.
getIfNoneMatch()
Return the value of the If-None-Match header.
getIfUnmodifiedSince()
Return the value of the If-Unmodified-Since header.
getLastModified()
Return the time the resource was last changed, as specified by the
Last-Modified header.
URI
getLocation()
Return the (new) location of a resource
as specified by the Location header.
getOrEmpty(Object headerName)
Get the list of header values for the given header name, if any.
getOrigin()
Return the value of the Origin header.
getPragma()
Return the value of the Pragma header.
List
getRange()
Return the value of the Range header.
getUpgrade()
Return the value of the Upgrade header.
getValuesAsList(String headerName)
Return all values of a given header name,
even if this header is set multiple times.
getVary()
Return the request header names subject to content negotiation.
int
hashCode()
isEmpty()
Set
keySet()
put(String key,
List value)
putAll(Map> map)
static HttpHeaders
readOnlyHttpHeaders(HttpHeaders headers)
Apply a read-only HttpHeaders wrapper around the given headers, if necessary.
readOnlyHttpHeaders(MultiValueMap headers)
remove(Object key)
set(String headerName,
Set the given, single header value under the given name.
setAccept(List acceptableMediaTypes)
Set the list of acceptable media types,
setAcceptCharset(List acceptableCharsets)
Set the list of acceptable charsets,
setAcceptLanguage(List languages)
Set the acceptable language ranges, as specified by the
Accept-Language header.
setAcceptLanguageAsLocales(List locales)
setAcceptPatch(List mediaTypes)
Set the list of acceptable media types for
setAccessControlAllowCredentials(boolean allowCredentials)
Set the (new) value of the Access-Control-Allow-Credentials response header.
setAccessControlAllowHeaders(List allowedHeaders)
Set the (new) value of the Access-Control-Allow-Headers response header.
setAccessControlAllowMethods(List allowedMethods)
Set the (new) value of the Access-Control-Allow-Methods response header.
setAccessControlAllowOrigin(String allowedOrigin)
Set the (new) value of the Access-Control-Allow-Origin response header.
setAccessControlExposeHeaders(List exposedHeaders)
Set the (new) value of the Access-Control-Expose-Headers response header.
setAccessControlMaxAge(Duration maxAge)
Set the (new) value of the Access-Control-Max-Age response header.
setAccessControlMaxAge(long maxAge)
setAccessControlRequestHeaders(List requestHeaders)
Set the (new) value of the Access-Control-Request-Headers request header.
setAccessControlRequestMethod(HttpMethod requestMethod)
Set the (new) value of the Access-Control-Request-Method request header.
setAll(Map values)
Set the given values under.
setAllow(Set allowedMethods)
Set the set of allowed HTTP methods,
setBasicAuth(String encodedCredentials)
setBasicAuth(String username,
String password)
Set the value of the Authorization header to
Basic Authentication based on the given username and password.
setBearerAuth(String token)
the given Bearer token.
setCacheControl(CacheControl cacheControl)
Set a configured CacheControl instance as the
new value of the Cache-Control header.
setCacheControl(String cacheControl)
Set the (new) value of the Cache-Control header.
setConnection(List connection)
Set the (new) value of the Connection header.
setConnection(String connection)
setContentDisposition(ContentDisposition contentDisposition)
Set the Content-Disposition header.
setContentDispositionFormData(String name,
String filename)
Set the Content-Disposition header when creating a
“multipart/form-data” request.
setContentLanguage(Locale locale)
Set the Locale of the content language,
as specified by the Content-Language header.
setContentLength(long contentLength)
Set the length of the body in bytes, as specified by the
setContentType(MediaType mediaType)
Set the media type of the body,
as specified by the Content-Type header.
setDate(Instant date)
Set the date and time at which the message was created, as specified
setDate(long date)
setDate(String headerName,
long date)
Set the given date under the given header name after formatting it as a string
using the RFC-1123 date-time formatter.
setDate(ZonedDateTime date)
setETag(String etag)
Set the (new) entity tag of the body, as specified by the ETag header.
setExpires(Instant expires)
Set the date and time at which the message is no longer valid,
setExpires(long expires)
setExpires(ZonedDateTime expires)
Set the duration after which the message is no longer valid,
setHost(InetSocketAddress host)
Set the (new) value of the Host header.
setIfMatch(List ifMatchList)
Set the (new) value of the If-Match header.
setIfMatch(String ifMatch)
setIfModifiedSince(Instant ifModifiedSince)
Set the time the resource was last changed, as specified by the
setIfModifiedSince(long ifModifiedSince)
Set the (new) value of the If-Modified-Since header.
setIfModifiedSince(ZonedDateTime ifModifiedSince)
setIfNoneMatch(List ifNoneMatchList)
Set the (new) values of the If-None-Match header.
setIfNoneMatch(String ifNoneMatch)
Set the (new) value of the If-None-Match header.
setIfUnmodifiedSince(Instant ifUnmodifiedSince)
setIfUnmodifiedSince(long ifUnmodifiedSince)
Set the (new) value of the If-Unmodified-Since header.
setIfUnmodifiedSince(ZonedDateTime ifUnmodifiedSince)
setInstant(String headerName,
Instant date)
setLastModified(Instant lastModified)
setLastModified(long lastModified)
setLastModified(ZonedDateTime lastModified)
setLocation(URI location)
Set the (new) location of a resource,
setOrigin(String origin)
Set the (new) value of the Origin header.
setPragma(String pragma)
Set the (new) value of the Pragma header.
setRange(List ranges)
Sets the (new) value of the Range header.
setUpgrade(String upgrade)
Set the (new) value of the Upgrade header.
setVary(List requestHeaders)
Set the request header names (e. g.
setZonedDateTime(String headerName,
ZonedDateTime date)
size()
toCommaDelimitedString(List headerValues)
Turn the given list of header values into a comma-delimited result.
Map
toSingleValueMap()
Return a Map with the first values contained in this MultiValueMap.
toString()
Collection>
values()
writableHttpHeaders(HttpHeaders headers)
Remove any read-only wrapper that may have been previously applied around
the given headers via readOnlyHttpHeaders(HttpHeaders).
What is HTTP Header? - Definition from Techopedia

What is HTTP Header? – Definition from Techopedia

HTTP headers are the name or value pairs that are displayed in the request and response messages of message headers for Hypertext Transfer Protocol (HTTP). Usually, the header name and the value are separated by a single colon. HTTP headers are an integral part of HTTP requests and simpler terms, HTTP headers are the code that transfers data between a Web server and a client. HTTP headers are mainly intended for the communication between the server and client in both directions.
HTTP headers can be classified into four types:Whenever you type a URL into the address bar and try to access it, your browser sends an HTTP request to the server. The HTTP request header contains information in a text-record form, which includes particulars such as the:Type, capabilities and version of the browser that generates the request. Operating system used by the that was rious types of outputs accepted by the receiving the request header, the Web server will send an HTTP response header back to the client. An HTTP response header includes information in a text-record form that a Web server transmits back to the client’s browser. The response header contains particulars such as the type, date and size of the file sent back by the server, as well as information regarding the headers contain directives that need to be followed, for both the requester and receiver. This can include information regarding:Caching directives. Specified connection date (always listed in Greenwich Mean TIme)PragmaUpgrade (for if the protocols need to be switched)Via (to indicate intermediate protocols)Warning (for additional information not found elsewhere in the header. There may be more than one warning listed. )These headers include information regarding:Allow (methods supported by the identified resource)Content ntent ntent ntent (for checking the integrity of the message upon receipt). Content ntent it it was last modified.
HttpHeaders (Java SE 11 & JDK 11 ) - Oracle Help Center

HttpHeaders (Java SE 11 & JDK 11 ) – Oracle Help Center

public final class HttpHeaders
extends Object
A read-only view of a set of HTTP headers.
An HttpHeaders is not typically created directly, but rather
returned from an HttpRequest or an
HttpResponse. Specific HTTP headers can be
set for a request through one of the request
builder’s headers methods.
The methods of this class ( that accept a String header name), and the
Map returned by the map method, operate without regard
to case when retrieving the header value(s).
An HTTP header name may appear more than once in the HTTP protocol. As
such, headers are represented as a name and a list of values. Each occurrence
of a header value is added verbatim, to the appropriate header name list,
without interpreting its value. In particular, HttpHeaders does not
perform any splitting or joining of comma separated header value strings. The
order of elements in a header value list is preserved when building a request. For
responses, the order of elements in a header value list is the order in which
they were received. The Map returned by the map method,
however, does not provide any guarantee with regard to the ordering of its
entries.
HttpHeaders instances are immutable.
Since:
11
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type
Method
Description
List
allValues​(String name)
Returns an unmodifiable List of all of the header string values of the
given named header.
boolean
equals​(Object obj)
Tests this HTTP headers instance for equality with the given object.
Optional
firstValue​(String name)
Returns an Optional containing the first header string value of
the given named (and possibly multi-valued) header.
OptionalLong
firstValueAsLong​(String name)
Returns an OptionalLong containing the first header string value
of the named header field.
int
hashCode()
Computes a hash code for this HTTP headers instance.
Map>
map()
Returns an unmodifiable multi Map view of this HttpHeaders.
static HttpHeaders
of​(Map> headerMap,
BiPredicate filter)
Returns an HTTP headers from the given map.
String
toString()
Returns this HTTP headers as a string.
Methods declared in class
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Method Detail
firstValue
public Optional firstValue​(String name)
the given named (and possibly multi-valued) header. If the header is not
present, then the returned Optional is empty.
Parameters:
name – the header name
Returns:
an Optional containing the first named header
string value, if present
firstValueAsLong
public OptionalLong firstValueAsLong​(String name)
of the named header field. If the header is not present, then the
Optional is empty. If the header is present but contains a value that
does not parse as a Long value, then an exception is thrown.
an OptionalLong
Throws:
NumberFormatException – if a value is found, but does not parse as
a Long
allValues
public List allValues​(String name)
given named header. Always returns a List, which may be empty if the
header is not present.
a List of headers string values
map
public Map> map()
the Map
equals
public final boolean equals​(Object obj)
If the given object is not an HttpHeaders then this
method returns false. Two HTTP headers are equal if each
of their corresponding maps are equal.
This method satisfies the general contract of the method.
Overrides:
equals in class Object
obj – the object to which this object is to be compared
true if, and only if, the given object is an
HttpHeaders that is equal to this HTTP headers
See Also:
Object. hashCode(),
HashMap
hashCode
public final int hashCode()
The hash code is based upon the components of the HTTP headers
map, and satisfies the general contract of the
Object. hashCode method.
hashCode in class Object
the hash-code value for this HTTP headers
(),
entityHashCode()
toString
public String toString()
toString in class Object
a string describing the HTTP headers
of
public static HttpHeaders of​(Map> headerMap,
Returns an HTTP headers from the given map. The given map’s key
represents the header name, and its value the list of string header
values for that header name.
An HTTP header name may appear more than once in the HTTP protocol.
Such, multi-valued, headers must be represented by a single entry
in the given map, whose entry value is a list that represents the
multiple header string values. Leading and trailing whitespaces are
removed from all string values retrieved from the given map and its lists
before processing. Only headers that, after filtering, contain at least
one, possibly empty string, value will be added to the HTTP headers.
API Note:
The primary purpose of this method is for testing frameworks.
Per-request headers can be set through one of the HttpRequest
headers methods.
headerMap – the map containing the header names and values
filter – a filter that can be used to inspect each
header-name-and-value pair in the given map to determine if
it should, or should not, be added to the to the HTTP
headers
an HTTP headers instance containing the given headers
NullPointerException – if any of: headerMap, a key or value
in the given map, or an entry in the map’s value list, or
filter, is null
IllegalArgumentException – if the given headerMap contains
any two keys that are equal ( without regard to case); or if the
given map contains any key whose length, after trimming
whitespaces, is 0
Report a bug or suggest an enhancement For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries. Copyright © 1993, 2021, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 rights reserved. Use is subject to license terms and the documentation redistribution policy.

Frequently Asked Questions about httpheaders

What is HttpHeaders?

HTTP headers are the name or value pairs that are displayed in the request and response messages of message headers for Hypertext Transfer Protocol (HTTP). … HTTP headers are an integral part of HTTP requests and responses. In simpler terms, HTTP headers are the code that transfers data between a Web server and a client.Aug 14, 2020

What is HttpHeaders in Java?

public final class HttpHeaders extends Object. A read-only view of a set of HTTP headers. An HttpHeaders is not typically created directly, but rather returned from an HttpRequest or an HttpResponse . Specific HTTP headers can be set for a request through one of the request builder’s headers methods.

What is HttpHeaders angular?

HTTP Headers let the client and the server share additional information about the HTTP request or response. For example, we use the content-type header to indicate the media type of the resource like JSON, text, blob, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *