Github user ato commented on the issue:
https://github.com/apache/httpcomponents-core/pull/70
> @ato What if we passed the original request message (or its request URI)
instead of linking the contexts?
For my use case the request message is a means to an end. I want to
associate an id or some application data with the request and then get it back
again so that I know what to do with that particular push when I receive it.
The URI alone wouldn't work as I might be making multiple requests to same
the URI such as multiple POSTs with a different body.
Technically I guess the identity of the request object would work as an id
but it would be somewhat indirect. I'd probably keep an
IdentityHashMap<HttpRequest,MyData> and then pass my per-request application
data into the context:
requestMap.put(request, context.getAttribute("mydata"));
client.execute(request, consumer, context, callback);
Then in push consumer I could get at it like:
var mydata = globalRequestMap.get(originalRequest);
Or I guess maybe subclass the request and add a field for my data?
Here's another alternative. What if rather than registering the
AsyncPushConsumers on the HttpClient you could pass a AsyncPushConsumer when
making the request:
var pushConsumer = new MyPushConsumer(mydata);
client.execute(request, responseConsumer, pushConsume);
That would totally solve my problem in a fairly clean way without exposing
the context or changing the AsyncPushConsumer interface.
I noticed that's how the JDK11 HttpClient solves this problem:
https://download.java.net/java/early_access/jdk11/docs/api/java.net.http/java/net/http/HttpClient.html#sendAsync(java.net.http.HttpRequest,java.net.http.HttpResponse.BodyHandler,java.net.http.HttpResponse.PushPromiseHandler)
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]