Set request headers

58 views
Skip to first unread message

Robin Green

unread,
May 8, 2013, 12:55:32 PM5/8/13
to raptur...@googlegroups.com
How can I set HTTP request headers such as Accept?

Jon Pretty

unread,
May 8, 2013, 1:14:33 PM5/8/13
to raptur...@googlegroups.com
Hi Robin,

These can be provided as a Map[String, String] in an optional parameter to the put or post methods, e.g.

   val content = json"{}" // Boring example...
   val url = Http / "example.com" / "endpoint"

   url.post(content, httpHeaders = Map(
     "Accept" -> "text/plain",
     "Accept-Language" -> "en-US"
   ))

Cheers,
Jon



2013/5/8 Robin Green <gre...@gmail.com>
How can I set HTTP request headers such as Accept?

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



--
Jon Pretty | Director

Propensive | forward-thinking design
+44 7974 771045 | propensive.com | @propensive
The Black Barn, Cliddesden, Hampshire, RG25 2JL.

Propensive Ltd is registered in England no 6873445.

Robin Green

unread,
May 8, 2013, 1:17:54 PM5/8/13
to raptur...@googlegroups.com, jon.p...@propensive.com
Thanks. I'd like to be able to set them for all request methods, including GET.

Jon Pretty

unread,
May 8, 2013, 1:21:18 PM5/8/13
to Robin Green, raptur...@googlegroups.com
Ah, that's something you can't do yet. I'll need to think about the best way of allowing that.  One possibility would be to add a get method alongside put and post, with the same semantics...

Hopefully I can slip a quick solution into version 0.8 which I'm hoping to get out the door this week.

Cheers,
Jon

Andy Hull

unread,
Aug 15, 2014, 6:50:51 PM8/15/14
to raptur...@googlegroups.com, gre...@gmail.com, jon.p...@propensive.com
Hey there,

Was this ever implemented? Can't find anything in the docs. The Rapture demo at Scala by the Bay was mind-blowing; I just really want to use it with OAuth bearer tokens!

Cheers,

--Andy

Jon Pretty

unread,
Aug 16, 2014, 12:59:19 PM8/16/14
to raptur...@googlegroups.com, gre...@gmail.com, jon.p...@propensive.com
Hi Andy,

Thanks!

I didn't spend any time covering the HTTP utilities in the talk, as this is less well tested than the other I/O tools, but it's something I do want to continue developing.

Nevertheless, the functionality is there - just be aware that it's more likely to have quirks...

Try this:

  import rapture.core.timeSystems.numeric // this is so we can specify the timeout in ms
  val request = uri"http://some.url.com/request".post(content = "some post data", timeout = 10000L, httpHeaders = Map("foo" -> "bar"))
  request.slurp[Char]

That should give you a string of the message.

There is also a thing called `Browser` which allows you to maintain cookie state between requests, though that's still experimental for now!

Sorry for the brief explanation. The documentation is very much a work-in-progress, but in case you haven't seen it yet, have a look at:

  https://github.com/propensive/rapture-io/blob/master/doc/introduction.md

which (although incomplete) should give you a reasonable overview of what's supported in Rapture IO.

Good luck!
Jon
Reply all
Reply to author
Forward
0 new messages