how to include header in HTTP.post

59 views
Skip to first unread message

Joe Fleck

unread,
Jan 18, 2019, 11:24:07 AM1/18/19
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Hi all,

Very new to HTTP.

I need to send in a header with a post to set the project cookie.  The header includes a session cookie that is needed to set the project cookie.

I thought something like this would work but it does.
HTTP.post("#{<endpoint url>", :json => {"key":<key>, "value":<value>}).header("Cookie":cookie)

Any help you would be greatly appreciated.

Thank you,
Joe

Slava Ptsarev

unread,
Jan 18, 2019, 11:47:30 AM1/18/19
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Hi Joe,

You'll need to do something like:
HTTP.headers('Set-Cookie' => '<cookie-name>=<cookie-value>; Domain=<domain-value>')

and add any info in that cookie string like Path or Expires etc. Also have a look at https://github.com/httprb/http/wiki/Headers

пятница, 18 января 2019 г., 19:24:07 UTC+3 пользователь Joe Fleck написал:

Tony Arcieri

unread,
Jan 18, 2019, 12:33:48 PM1/18/19
to Slava Ptsarev, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
It's becoming increasingly clear to me our cookie handling could be significantly better.

I think this API could be improved with a hypothetical HTTP::Session type which manages a CookieJar:


--
Tony Arcieri

Joe Fleck

unread,
Jan 18, 2019, 1:39:07 PM1/18/19
to Tony Arcieri, Slava Ptsarev, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Hi Slava,

Should that be an array?

Joe



--
You received this message because you are subscribed to the Google Groups "http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to httprb+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Fleck

unread,
Jan 18, 2019, 2:02:25 PM1/18/19
to Tony Arcieri, Slava Ptsarev, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
I feel like I am there but still getting an unauthorized return status.

HTTP.headers("Set-Cookie" => "<cookie>=<value>").post(<URL>, :json => {""}).

Aleksey Zapparov

unread,
Jan 18, 2019, 2:34:44 PM1/18/19
to Joe Fleck, Tony Arcieri, Slava Ptsarev, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Set-Cookie is a server response, not client's header. It instructs client to set cookie. Client sends cookies with Cookie header.

What you need is:

HTTP.cookies("foo" => "bar").get(...)

Aleksey Zapparov

unread,
Jan 18, 2019, 2:38:46 PM1/18/19
to Joe Fleck, Tony Arcieri, Slava Ptsarev, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Alternatively you can provide cookie header yourself:

HTTP.headers("Cookie" => "foo=bar;xxx=zzz")

Above is same as:

HTTP.cookies("foo" => "bar", "xxx" => "zzz")
Reply all
Reply to author
Forward
0 new messages