# Cookiejar without cgi

**URL:** <https://www.ruby-forum.com/t/cookiejar-without-cgi/182657>\
**Category:** Ruby\
**Created:** [February 1, 2010, 7:26am UTC](https://www.ruby-forum.com/t/cookiejar-without-cgi/182657 "2010-02-01T07:26:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 1, 2010, 7:26am UTC](https://www.ruby-forum.com/t/cookiejar-without-cgi/182657/1 "2010-02-01T07:26:22Z")

</div>

How do you create a cookiejar? I googled:

ruby cookiejar example create help -bowling -rails -python -java -php  
-pottery -ceramic -lyric -lyrics

and just can’t find an example. Here’s what I have:

require ‘rubygems’  
require ‘curb’  
require ‘cgi’

cookie = CGI::Cookie.new  
(“SID”,“[domain=.google.com](http://domain=.google.com)”,“path=/”,“expires=1600000000”)

puts cookie.inspect  
puts cookie.to\_s

#add cookie to cookiejar, and use curb  
#c = Curl::Easy.http\_post “[https://www.google.com/accounts/](https://www.google.com/accounts/)  
ClientLogin”,

How can I do that without cgi?

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 1, 2010, 3:04pm UTC](https://www.ruby-forum.com/t/cookiejar-without-cgi/182657/2 "2010-02-01T15:04:59Z")

</div>

Thufir wrote:

> Here’s what I have:
> 
> require ‘rubygems’  
> require ‘curb’  
> require ‘cgi’
> 
> cookie = CGI::Cookie.new  
> (“SID”,“[domain=.google.com](http://domain=.google.com)”,“path=/”,“expires=1600000000”)
> 
> puts cookie.inspect  
> puts cookie.to\_s  
> …  
> How can I do that without cgi?

By emitting a Set-Cookie: header directly?

> **[HTTP cookie | Implementation](https://en.wikipedia.org/wiki/HTTP_cookie#Implementation)**
>
> Cookies are arbitrary pieces of data, usually chosen and first sent by the web server, and stored on the client computer by the web browser. The browser then sends them back to the server with every request, introducing states (memory of previous events) into otherwise stateless HTTP transactions. Without cookies, each retrieval of a web page or component of a web page would be an isolated event, largely unrelated to all other page views made by the user on the website. Although cookies are usual...

You can always look at the source of CGI::Cookie to see what it does,  
and incorporate the bits you want. What’s the reason for not using it?

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 1, 2010, 7:30pm UTC](https://www.ruby-forum.com/t/cookiejar-without-cgi/182657/3 "2010-02-01T19:30:34Z")

</div>

On Feb 1, 6:05 am, Brian C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
[…]

> > How can I do that without cgi?
> 
> By emitting a Set-Cookie: header directly?[HTTP cookie - Wikipedia](http://en.wikipedia.org/wiki/HTTP_cookie#Implementation)
> 
> You can always look at the source of CGI::Cookie to see what it does,  
> and incorporate the bits you want. What’s the reason for not using it?

What I meant to ask is how to do that from the curb library. There’s:

curl = Curl::Easy.new(‘[http://example.com/](http://example.com/)’)  
curl.cookies = ‘auth=abcdef; ASP.NET\_SessionId=big-wall-of-text;’  
curl.perform

[http://blog.codefront.net/2009/06/18/better-cookie-support-in-curb/](http://blog.codefront.net/2009/06/18/better-cookie-support-in-curb/)

but can the curb API create the same cookie as the cgi API, and, if  
so, how? For convenience, I’d like to use just as few different API’s  
as possible, where possible. Alternately, how can that cookie created  
from the cgi API be used by the curb API? Add the cookie to a  
cookiejar which curb can access?

-Thufir
