desiderantes commented on code in PR #846:
URL:
https://github.com/apache/httpcomponents-client/pull/846#discussion_r3589342083
##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CacheKeyGenerator.java:
##########
@@ -138,13 +173,62 @@ public String generateKey(final URI requestUri) {
*/
public String generateKey(final HttpHost host, final HttpRequest request) {
final String s = CacheSupport.requestUriRaw(host, request);
+ final String hash = Method.QUERY.isSame(request.getMethod()) ?
getBodyHash(request) : null;
try {
- return generateKey(new URI(s));
+ return generateKey(new URI(s), hash);
} catch (final URISyntaxException ex) {
return s;
}
}
+ protected byte[] getRequestBodyBytes(final HttpRequest request) {
+ if (bodyBytesExtractor != null) {
+ final byte[] bytes = bodyBytesExtractor.apply(request);
+ if (bytes != null) {
+ return bytes;
+ }
+ }
+ if (request instanceof SimpleHttpRequest) {
+ return ((SimpleHttpRequest) request).getBodyBytes();
+ }
+ if (request instanceof ClassicHttpRequest) {
+ final HttpEntity entity = ((ClassicHttpRequest)
request).getEntity();
+ if (entity != null) {
+ try {
+ if (entity.isRepeatable()) {
+ final byte[] bytes = EntityUtils.toByteArray(entity);
+ ((ClassicHttpRequest) request).setEntity(new
ByteArrayEntity(bytes, ContentType.parse(entity.getContentType())));
+ return bytes;
+ }
+ } catch (final Exception ignore) {
+ }
+ }
+ }
+ return null;
Review Comment:
ok, yes, if null is not an option, this doesn't work. I'll take a look at
that PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]