How do I pass a cookie to a Sinatra app using curl?

Posted by Brandon Toone on Stack Overflow See other posts from Stack Overflow or by Brandon Toone
Published on 2010-04-22T17:20:47Z Indexed on 2010/04/22 17:23 UTC
Read the original article Hit count: 504

Filed under:
|
|
|
|

I'm using the code from the example titled "A Slightly Bigger Example" from this tutorial http://rubylearning.com/blog/2009/09/30/cookie-based-sessions-in-sinatra/ to figure out how to send a cookie to a Sinatra application but I can't figure out how to set the values correctly

When I set the name to be "brandon" in the application it creates a cookie with a value of BAh7BiIJdXNlciIMYnJhbmRvbg%3D%3D%0A which is a url encoding (http://ostermiller.org/calc/encode.html) of the value BAh7BiIJdXNlciIMYnJhbmRvbg==

Using that value I can send a cookie to the app correctly

curl -b "rack.session=BAh7BiIJdXNlciIMYnJhbmRvbg==" localhost:9393

I'm pretty sure that value is a base64 encoding of the ruby hash for the session since the docs (http://rack.rubyforge.org/doc/classes/Rack/Session/Cookie.html) say

The session is a Ruby Hash stored as base64 encoded marshalled data set to :key (default: rack.session).

I thought that meant all I had to do was base64 encode {"user"=>"brandon"} and use it in the curl command. Unfortunately that creates a different value than BAh7BiIJdXNlciIMYnJhbmRvbg==. Next I tried taking the base64 encoded value and decoding it at various base64 decoders online but that results in strange characters (a box symbol and others) so I don't know how to recreate the value to even encode it.

So my question is do you know what characters/format I need to get the proper base64 encoding and/or do you know of another way to pass a value using curl such that it will register as a proper cookie for a Sinatra app?

© Stack Overflow or respective owner

Related posts about curl

Related posts about sinatra