pythonhttpie

Remove default HTTP Headers from HTTPie's request


There are a couple of default headers that HTTPie sets. I'm wondering if there is a way to remove some header, like Accept-Encoding?

The reason I like to unset Accept-Encoding is to check our server's behavior about HTTP Compression.


Solution

  • Add the Headers follow by a colon.

    http -v https://jsonplaceholder.typicode.com/todos/1 \
         Accept: \
         Accept-Encoding: \
         Connection: \
         Host: \
         User-Agent: 
    

    Request:

    GET /todos/1 HTTP/1.1
    Host: jsonplaceholder.typicode.com
    

    Response:

    HTTP/1.1 200 OK
    ...
    
    http -v https://jsonplaceholder.typicode.com/todos/1
    

    Request:

    GET /todos/1 HTTP/1.1
    Accept: */*
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    Host: jsonplaceholder.typicode.com
    User-Agent: HTTPie/0.9.8
    

    Response:

    HTTP/1.1 200 OK
    ...
    

    The -v option display the request. Also, remember no spaces after \ in multiline bash commands.