Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom User-Agent not remembered during session #180

Closed
karlcow opened this issue Nov 22, 2013 · 4 comments
Closed

Custom User-Agent not remembered during session #180

karlcow opened this issue Nov 22, 2013 · 4 comments
Labels
bug Something isn't working

Comments

@karlcow
Copy link

karlcow commented Nov 22, 2013

When testing it is often useful to have a set of predefined profiles such as different set of headers for different browsers. It helps with testing Web sites.

One way to do that currently is to create a variable for each profile.

→ export FOO="blah:X Yada:Z"
→ echo $FOO
blah:X Yada:Z
→ http --print hH GET http://www.example.org/ $FOO
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, compress
Host: www.example.org
User-Agent: HTTPie/0.7.2
Yada: Z
blah: X

HTTP/1.1 200 OK
[…]

but it would be entirely possible to have a feature such as

http --profile foo GET http://example.org/

where foo is a JSON file in .httpie/profiles/foo.json

@miketaylr
Copy link

I would love this feature. 👍

@jkbrzt
Copy link
Member

jkbrzt commented Nov 22, 2013

HTTPie supports sessions that allow you to do this. Example:

Create a session file:

$ http --session=/tmp/foo.json example.org blah:X Yada:Z

# or, you can also create the file manually:
$ echo '
{    
    "headers": {
        "Yada": "Z",
        "blah": "X"
    }
}' > /tmp/foo.json

Reuse it whenever needed:

$ http -v --session=/tmp/foo.json example.org
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, compress
Host: example.org
User-Agent: HTTPie/0.8.0-dev
Yada: Z
blah: X

Please see https://github.com/jkbr/httpie#sessions for more details.

@jkbrzt jkbrzt closed this as completed Nov 23, 2013
@karlcow
Copy link
Author

karlcow commented Dec 18, 2013

I guess we can reopen the issue because it is not what we were expecting.

Let's say we create the JSON file:

{ "headers": {
    "User-Agent": "Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0", 
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "Accept-Language": "en-us,en;q=0.5",
    "Accept-Encoding":  "gzip, deflate",
    "DNT": "1"
    }
}

Following your instructions, I do

→ http --print hH --session=./firefox-os.json GET http://www.mozilla.org/

which is leading to:

GET / HTTP/1.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-us,en;q=0.5
DNT: 1
Host: www.mozilla.org
User-Agent: HTTPie/0.7.2

HTTP/1.1 301 Moved Permanently
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, private, max-age=900
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Wed, 18 Dec 2013 21:01:27 GMT
Expires: Wed, 18 Dec 2013 21:16:27 GMT
Location: http://www.mozilla.org/en-US/
Pragma: no-cache
Server: Apache
Vary: User-Agent,Accept-Language
X-Backend-Server: bedrock4.webapp.scl3.mozilla.com
X-Cache-Info: not cacheable; response specified "Cache-Control: no-store"
X-Robots-Tag: noodp

The first anomaly is User-Agent: HTTPie/0.7.2.
Then HTTPie is rewriting the session file to

{
    "__meta__": {
        "about": "HTTPie session file", 
        "help": "https://github.com/jkbr/httpie#sessions", 
        "httpie": "0.7.2"
    }, 
    "auth": {
        "password": null, 
        "type": null, 
        "username": null
    }, 
    "cookies": {}, 
    "headers": {
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
        "Accept-Encoding": "gzip, deflate", 
        "Accept-Language": "en-us,en;q=0.5", 
        "DNT": "1", 
        "User-Agent": "Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0"
    }
}

So not working.

@karlcow
Copy link
Author

karlcow commented Dec 18, 2013

This will solve the rewriting

http --print hH --session-read-only=./firefox-os.json GET http://www.mozilla.org/

The User-Agent is still not working. I tried reordering the json file but without success.

@jkbrzt jkbrzt reopened this Dec 18, 2013
@jkbrzt jkbrzt changed the title Profile of headers for HTTP requests Custom User-Agent not remembered during session May 6, 2014
@jkbrzt jkbrzt added the bug label May 6, 2014
@jkbrzt jkbrzt closed this as completed in 858555a May 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants