How to change default value of header user-agent

1,201 views
Skip to first unread message

Karun Kumar

unread,
May 12, 2014, 3:23:30 AM5/12/14
to swagger-sw...@googlegroups.com
Hi Guys,

How to change default value of user-agent to android or ios. Because i need sent to rest API.

My rest api will take parameter as @Context HttpHeaders paramHttpHeaders.

Can some body help me in setting user-agent value in HttpHeaders with swagger.

Regards,
Karuna

Ron

unread,
May 12, 2014, 7:42:18 AM5/12/14
to swagger-sw...@googlegroups.com
To clarify, Swagger doesn't send anything, it's just describing your API.

A header parameter can be added to your operations via regular operation parameters or with api-key authorization.

Or are you referring to the code being produced by the codegen?


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Karun Kumar

unread,
May 13, 2014, 2:22:29 AM5/13/14
to swagger-sw...@googlegroups.com
Hi Ron,
Thanks for your reply.
Actually I need to change uesr-agent value as "Andriod".
By default it's value is 
User-AgentMozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
But I need to change this value to Andriod.

Thanks,
Karuna
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Karun Kumar

unread,
May 13, 2014, 2:39:05 AM5/13/14
to swagger-sw...@googlegroups.com

Hi Ron,
Thanks for your reply.
Actually I need to change uesr-agent value as "Andriod".
By default it's value is 
User-AgentMozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
But I need to change this value to Andriod.

Thanks,
Karuna
On Monday, 12 May 2014 17:12:18 UTC+5:30, Ron R wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron

unread,
May 13, 2014, 2:56:07 AM5/13/14
to swagger-sw...@googlegroups.com
I assume you refer to the swagger-ui part.
The use agent being sent is controlled by your browser, and depending on your browser there are plugins available to override the user-agent.
I imagine there's a way to control it via javascript as well, but I'm no expert. I'm sure google can help with that. Here's a sample result - http://hynchrstn.wordpress.com/2011/11/24/make-custom-javascript-navigator-useragent/


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Karuna Kumar

unread,
May 23, 2014, 7:41:16 AM5/23/14
to swagger-sw...@googlegroups.com
Hi Ron,

Is it possible to set useragent value for on request only not for all request.

Regards,
Karuna
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsubscri...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron

unread,
May 23, 2014, 8:51:53 AM5/23/14
to swagger-sw...@googlegroups.com
Sorry, I don't understand your question.


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Karun Kumar

unread,
May 23, 2014, 9:23:42 AM5/23/14
to swagger-sw...@googlegroups.com
Hi Ron,
As per previous post, my task is i need add user-agent value for one of my post request as @context httpheaders.

Response submit(@Context HttpHeaders paramHttpHeaders){
//do something
}

Here in paramHttpHeaders, when I set user-agent value, then it is taking default value.

Regards,
Karuna



You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/nxtWlEy0W3Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Regards
Karun

Ron

unread,
May 23, 2014, 9:53:36 AM5/23/14
to swagger-sw...@googlegroups.com
The user-agent is an HTTP header sent by the client to identify the client type (normally, the browser id).

You can specify that it is first need to add the user client as a header authentication. I only have an example of how it would look like in the scala code, but it's easy to do the same in java - https://github.com/wordnik/swagger-core/blob/8abac0ca61ca5a497adf481256ac2b79d18c34f0/samples/scala-jaxrs-fileupload/src/main/scala/com/wordnik/swagger/sample/Bootstrap.scala#L28 (you can also see the java code to generally add authorization definitions here - https://github.com/wordnik/swagger-core/blob/8abac0ca61ca5a497adf481256ac2b79d18c34f0/samples/java-jaxrs/src/main/java/com/wordnik/swagger/sample/Bootstrap.java).

Then annotate the operation you want to have the authorization to using @Authorization and give it the value of the name of the authentication scheme you previously defined.
Reply all
Reply to author
Forward
0 new messages