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

Open
droope opened this Issue Apr 27, 2014 · 3 comments

Comments

Projects
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.

#!/bin/bash
                                                                                                                                         . include.sh

function accept_terms {
    email="john_ra+86@zoho.com"                                                                                                                                     
    # login
    #http $sess https://coinbase.com/signin
    csrf_token=`http $sess https://site.com/signin | grep 'csrf-token' | awk -F'"' '{print $2}' | awk -F'"' '{print $1}'`

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

    # accept terms
    http $sess -f POST https://site.com/users/accept_terms "_method=post" "authenticity_token=$csrf_token"
}

accept_terms

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!

Thanks,
Pedro

Owner

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:

~/.httpie/sessions/<host>/<session>.json:

{
    "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 (https://docs.python.org/2/library/cookielib.html)

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

ta,
Pedro

@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