Updates the fromApacheHttpResponse method to fix an issue with duplicate headers
The Bug Fix
New builds were receiving the following error:
java.lang.IllegalStateException: Duplicate key Server-Timing (attempted merging values cfCacheStatus;desc="HIT" and cfEdge;dur=4,cfOrigin;dur=0)
at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:135)
at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Collectors.java:182)
at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:727)
at com.bitpay.sdk.client.HttpResponseProvider.fromApacheHttpResponse(HttpResponseProvider.java:29)
at com.bitpay.sdk.functional.client.HttpResponseProviderTest.it_should_correct_transfer_apache_response_to_bitpay_response(HttpResponseProviderTest.java:25)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
Running tests was throwing this due to the call that's made to https://jsonplaceholder.typicode.com/posts/1. They must have started using Cloudflare (or something changed) and multiple Server-Timing headers were being received.
This is a functional test, so I think it makes sense that we're calling JSON Placeholder, but we might consider replacing it in the future with a mocked call.
That said, it did uncover an issue where our client was not handling duplicate headers well, and if the BitPay API started to send duplicate headers, there could be a potential crash so I've implemented a change that will combine like headers into one.
I've confirmed that after the change, the Site-Timing header is changed to:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR performs two changes:
The Bug Fix
New builds were receiving the following error:
Running tests was throwing this due to the call that's made to https://jsonplaceholder.typicode.com/posts/1. They must have started using Cloudflare (or something changed) and multiple Server-Timing headers were being received.
This is a functional test, so I think it makes sense that we're calling JSON Placeholder, but we might consider replacing it in the future with a mocked call.
That said, it did uncover an issue where our client was not handling duplicate headers well, and if the BitPay API started to send duplicate headers, there could be a potential crash so I've implemented a change that will combine like headers into one.
I've confirmed that after the change, the Site-Timing header is changed to:
Closes #382