Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPCLIENT-2277: RFC 9111 conformance improvements / bug fixes #501

Merged
merged 8 commits into from
Nov 16, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ public Iterator<Header> headerIterator(final String name) {
return responseHeaders.headerIterator(name);
}

/**
* @since 5.3
*/
public MessageHeaders responseHeaders() {
return responseHeaders;
}

/**
* Gets the Date value of the "Date" header or null if the header is missing or cannot be
* parsed.
Expand Down Expand Up @@ -440,13 +447,27 @@ public String getRequestURI() {
return requestURI;
}

/**
* @since 5.3
*/
public MessageHeaders requestHeaders() {
return requestHeaders;
}

/**
* @since 5.3
*/
public Iterator<Header> requestHeaderIterator() {
return requestHeaders.headerIterator();
}

/**
* @since 5.3
*/
public Iterator<Header> requestHeaderIterator(final String headerName) {
return requestHeaders.headerIterator(headerName);
}

/**
* Tests if the given {@link HttpCacheEntry} is newer than the given {@link MessageHeaders}
* by comparing values of their {@literal DATE} header. In case the given entry, or the message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ public HttpCacheEntry create(final Instant requestInstant,
final String s = CacheKeyGenerator.getRequestUri(host, request);
final URI uri = CacheKeyGenerator.normalize(s);
final HeaderGroup requestHeaders = filterHopByHopHeaders(request);
// Strip AUTHORIZATION from request headers
requestHeaders.removeHeaders(HttpHeaders.AUTHORIZATION);
final HeaderGroup responseHeaders = filterHopByHopHeaders(response);
ensureDate(responseHeaders, responseInstant);
return new HttpCacheEntry(
Expand All @@ -232,12 +234,16 @@ public HttpCacheEntry create(final Instant requestInstant,
*
* @param requestInstant Date/time when the request was made (Used for age calculations)
* @param responseInstant Date/time that the response came back (Used for age calculations)
* @param host Target host
* @param request Original client request (a deep copy of this object is made)
* @param response Origin response (a deep copy of this object is made)
* @param entry Existing cache entry.
*/
public HttpCacheEntry createUpdated(
final Instant requestInstant,
final Instant responseInstant,
final HttpHost host,
final HttpRequest request,
final HttpResponse response,
final HttpCacheEntry entry) {
Args.notNull(requestInstant, "Request instant");
Expand All @@ -249,13 +255,18 @@ public HttpCacheEntry createUpdated(
if (HttpCacheEntry.isNewer(entry, response)) {
return entry;
}
final String s = CacheKeyGenerator.getRequestUri(host, request);
final URI uri = CacheKeyGenerator.normalize(s);
final HeaderGroup requestHeaders = filterHopByHopHeaders(request);
// Strip AUTHORIZATION from request headers
requestHeaders.removeHeaders(HttpHeaders.AUTHORIZATION);
final HeaderGroup mergedHeaders = mergeHeaders(entry, response);
return new HttpCacheEntry(
requestInstant,
responseInstant,
entry.getRequestMethod(),
entry.getRequestURI(),
headers(entry.requestHeaderIterator()),
request.getMethod(),
uri.toASCIIString(),
requestHeaders,
entry.getStatus(),
mergedHeaders,
entry.getResource(),
Expand Down
Loading