Passing user agent to endpoint

View: New views
4 Messages — Rating Filter:   Alert me  

Passing user agent to endpoint

by Coulombe, Greg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I'm trying to write a proxy that passes the caller's HTTP user agent
through to the target endpoint. Currently, the user agent is being
removed from the incoming request and replaced with the Synapse user
agent. Is it possible to prevent this behavior or explicitly set the
user agent for the outgoing request? From what I can tell, the
org.apache.synapse.transport.nhttp.HttpCoreNIOSender#invoke method calls
removeUnwantedHeaders before it processes the outgoing request. This is
the method that explicitly removes the user agent.

Thanks,

Greg

Re: Passing user agent to endpoint

by Asankha C. Perera :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Greg
> I'm trying to write a proxy that passes the caller's HTTP user agent
> through to the target endpoint. Currently, the user agent is being
> removed from the incoming request and replaced with the Synapse user
> agent. Is it possible to prevent this behavior or explicitly set the
> user agent for the outgoing request? From what I can tell, the
> org.apache.synapse.transport.nhttp.HttpCoreNIOSender#invoke method calls
> removeUnwantedHeaders before it processes the outgoing request. This is
> the method that explicitly removes the user agent.
>  
Hmm.. I think its right to replace the user agent, since to the backend
service that receives a request from Synapse, the user agent "is"
Synapse..  Do you think this is wrong?

However, if you set a custom user agent header as a Synapse transport
header during mediation, thats applied after the above method call and
it "may" work.. I cannot tell you for sure until you try it out, since
we do however hard code the user agent via a request handler. Best is to
give that a try as a workaround.. however I am free to consider
retaining the user agent header if there is a compelling reason - but so
far this is the first time I've heard this request from a user

cheers
asankha

--
Asankha C. Perera
AdroitLogic, http://adroitlogic.org

http://esbmagic.blogspot.com





RE: Passing user agent to endpoint

by Coulombe, Greg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Asankha,

I agree with what you are saying about replacing the UA being the "right
thing" for most use cases. In this case, the app to which I'm forwarding
my requests has some conditional logic based on the UA in the request so
I do need to pass it through. I tried just setting a transport header
but I'm not having any results. I'll keep trying and see what I can do.
Failing that, is there any place in the process where I can inject some
custom code _after_ the transport headers have been set for the outgoing
request? Maybe in a Formatter?

Thanks,

--GKC

-----Original Message-----
From: Asankha Perera [mailto:asankha.apache@...] On Behalf Of
Asankha C. Perera
Sent: Monday, September 21, 2009 9:20 AM
To: user@...
Subject: Re: Passing user agent to endpoint

Hi Greg
> I'm trying to write a proxy that passes the caller's HTTP user agent
> through to the target endpoint. Currently, the user agent is being
> removed from the incoming request and replaced with the Synapse user
> agent. Is it possible to prevent this behavior or explicitly set the
> user agent for the outgoing request? From what I can tell, the
> org.apache.synapse.transport.nhttp.HttpCoreNIOSender#invoke method
calls
> removeUnwantedHeaders before it processes the outgoing request. This
is
> the method that explicitly removes the user agent.
>  
Hmm.. I think its right to replace the user agent, since to the backend
service that receives a request from Synapse, the user agent "is"
Synapse..  Do you think this is wrong?

However, if you set a custom user agent header as a Synapse transport
header during mediation, thats applied after the above method call and
it "may" work.. I cannot tell you for sure until you try it out, since
we do however hard code the user agent via a request handler. Best is to
give that a try as a workaround.. however I am free to consider
retaining the user agent header if there is a compelling reason - but so
far this is the first time I've heard this request from a user

cheers
asankha

--
Asankha C. Perera
AdroitLogic, http://adroitlogic.org

http://esbmagic.blogspot.com





Re: Passing user agent to endpoint

by Asankha C. Perera :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Greg
> I agree with what you are saying about replacing the UA being the "right
> thing" for most use cases. In this case, the app to which I'm forwarding
> my requests has some conditional logic based on the UA in the request so
> I do need to pass it through.
Ok.. I think this is quite valid.. so maybe a enhancement request would
be good so that we can implement a feature to turn off replacing UA
>  I tried just setting a transport header
> but I'm not having any results. I'll keep trying and see what I can do.
>  
Ok.. if you've tried this, there is no way to get it to work with the
stock code unless you patch it..
> Failing that, is there any place in the process where I can inject some
> custom code _after_ the transport headers have been set for the outgoing
> request? Maybe in a Formatter?
>  
No, this is because its set as a transport level parameter when the
transports are initialized. If you are willing to create or use a
patched version, it would be a simple fix however.

cheers
asankha

--
Asankha C. Perera
AdroitLogic, http://adroitlogic.org

http://esbmagic.blogspot.com