Adding cookie to cookiejar (or allowing multiple Cookie: headers) #214

droope opened this Issue Apr 27, 2014 · 3 comments


None yet
3 participants

droope commented Apr 27, 2014

Hi there,

I am having issues with httpie in a rather contrived use-case. I was hoping that I perhaps help people solve this issue in the future or rather get some suggestions on how to solve it myself.

The issue arises when a server expects a cookie set by the client side using JS. In order to work around this, I need to add a cookie with a static value to my session. I was hoping to do so in a way similar to this.


function accept_terms {
    # login
    #http $sess
    csrf_token=`http $sess | grep 'csrf-token' | awk -F'"' '{print $2}' | awk -F'"' '{print $1}'`

   # this line below >>>
    http $sess -f POST "Cookie:df=579d23557fc4619cb01656425512a9db" "utf8=%E2%9C%93" "authenticity_token=$csrf_token" "email=$email" "pas#

    # accept terms
    http $sess -f POST "_method=post" "authenticity_token=$csrf_token"


In the line where I set the cookie header, httpie replaces the session cookie with the cookie I manually set. I've checked and if I were allowed to put two cookie headers apache would accept it, albeit a method to embed a custom cookie into the cookiejar might be a bit tidier!



jakubroztocil commented May 5, 2014

The of merging client- and. server-provided cookies within an HTTPie session isn't currently handled very well.

For now, you can work it around by adding the extra cookie to the session file manually:


    "cookies": {
        "df": {"value": "579d23557fc4619cb01656425512a9db"}

droope commented May 11, 2014

Hi jakubroztocil,

Yeah, that's what I did, worked 10/10. =)

I was wondering, if one were to attempt to fix this, where would one go? I've looked down the rabbit hole before opening the issue, and I think the problem lay with a standard python library (

Thinking about it, though, it's very likely that I am not right :P


@droope what makes you blame cookielib? It's a very good library, and I've never run into issues with it.

@jakubroztocil what extra handling of cookies does httpie do on top of what requests already handles for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment