Package com.launchdarkly.eventsource
Interface ResponseHeaders
public interface ResponseHeaders
This interface provides access to HTTP response headers in a way that is independent
of any specific HTTP client implementation. Headers are represented as an ordered list
of name-value pairs, preserving the original structure including duplicate header names.
Implementations of this interface should be immutable and thread-safe.
- Since:
- 4.2.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classRepresents a single HTTP header as a name-value pair. -
Method Summary
Modifier and TypeMethodDescriptionget(int index) Returns the header at the specified index.booleanisEmpty()Returns true if this collection contains no headers.intsize()Returns the number of headers in this collection.Returns the value of the first header with the specified name (case-insensitive), or null if no such header exists.
-
Method Details
-
size
int size()Returns the number of headers in this collection.Note that if a header name appears multiple times (e.g., multiple
Set-Cookieheaders), each appearance is counted separately.- Returns:
- the number of headers
-
get
Returns the header at the specified index.Headers are indexed in the order they appeared in the HTTP response.
- Parameters:
index- the index of the header to retrieve (0-based)- Returns:
- the header at the specified index
- Throws:
IndexOutOfBoundsException- if the index is out of range
-
value
Returns the value of the first header with the specified name (case-insensitive), or null if no such header exists.This is a convenience method for headers where you expect a single value. If the header appears multiple times in the response, only the first occurrence is returned.
Note that the returned value may contain commas if:
- The original HTTP response had a comma in the header value, or
- The HTTP client combined multiple header lines into one (though this is uncommon with the underlying OkHttp implementation)
For headers that can legitimately appear multiple times (like
Set-Cookie), usesize()andget(int)to iterate through all occurrences instead.Example usage:
String contentType = headers.value("Content-Type"); String retryAfter = headers.value("Retry-After");- Parameters:
name- the header name (case-insensitive)- Returns:
- the value of the first matching header, or null if not found
-
isEmpty
boolean isEmpty()Returns true if this collection contains no headers.- Returns:
- true if there are no headers
-