Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

/**
* A collection of headers on an HTTP request or response.
*/
public class HttpHeaders implements Iterable<HttpHeader> {
private final Map<String, HttpHeader> headers = new HashMap<>();
private final Map<String, HttpHeader> headers = new ConcurrentHashMap<>();

/**
* Create an empty HttpHeaders instance.
Expand Down Expand Up @@ -55,9 +56,9 @@ public int getSize() {
}

/**
* Set a header.
* Sets a {@link HttpHeader header} with the given name and value.
*
* If header with same name already exists then the value will be overwritten.
* <p>If header with same name already exists then the value will be overwritten.</p>
*
* @param name the name
* @param value the value
Expand All @@ -69,7 +70,8 @@ public HttpHeaders put(String name, String value) {
}

/**
* Get the {@link HttpHeader header} for the provided header name. Null will be returned if the header isn't found.
* Gets the {@link HttpHeader header} for the provided header name. {@code Null} is returned if the header isn't
* found.
*
* @param name the name of the header to find.
* @return the header if found, null otherwise.
Expand All @@ -79,22 +81,33 @@ public HttpHeader get(String name) {
}

/**
* Get the header value for the provided header name. Null will be returned if the header
* name isn't found.
* Removes the {@link HttpHeader header} with the provided header name. {@code Null} is returned if the header
* isn't found.
*
* @param name the name of the header to look for
* @return The String value of the header, or null if the header isn't found
* @param name the name of the header to remove.
* @return the header if removed, null otherwise.
*/
public HttpHeader remove(String name) {
return headers.remove(formatKey(name));
}

/**
* Get the value for the provided header name. {@code Null} is returned if the header name isn't found.
*
* @param name the name of the header whose value is being retrieved.
* @return the value of the header, or null if the header isn't found
*/
public String getValue(String name) {
final HttpHeader header = get(name);
return header == null ? null : header.getValue();
}

/**
* Get the header values for the provided header name. Null will be returned if
* the header name isn't found.
* Get the values for the provided header name. {@code Null} is returned if the header name isn't found.
*
* <p>This returns {@link #getValue(String) getValue} split by {@code comma}.</p>
*
* @param name the name of the header to look for
* @param name the name of the header whose value is being retrieved.
* @return the values of the header, or null if the header isn't found
*/
public String[] getValues(String name) {
Expand All @@ -107,7 +120,7 @@ private String formatKey(final String key) {
}

/**
* Get {@link Map} representation of the HttpHeaders collection.
* Gets a {@link Map} representation of the HttpHeaders collection.
*
* @return the headers as map
*/
Expand Down