• Posts
  • RSS
  • ◂◂RSS
  • Contact

  • Debug Headers with GET

    November 17th, 2020
    tech  [html]
    HTTP offers a convenient way to download only the headers: send a HEAD request:
    $ telnet www.example.com 80
    Trying 93.184.216.34...
    Connected to www.example.com.
    Escape character is '^]'.
    HEAD / HTTP/1.1
    Host: www.example.com
    
    HTTP/1.1 200 OK
    Content-Encoding: gzip
    Accept-Ranges: bytes
    Age: 325063
    Cache-Control: max-age=604800
    Content-Type: text/html; charset=UTF-8
    Date: Tue, 17 Nov 2020 02:29:50 GMT
    Etag: "3147526947"
    Expires: Tue, 24 Nov 2020 02:29:50 GMT
    Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
    Server: ECS (dcb/7F82)
    X-Cache: HIT
    Content-Length: 648
    
    Of course you wouldn't usually manually type into telnet, you'd use something like curl:
    $ curl -I http://www.example.com
    HTTP/1.1 200 OK
    Accept-Ranges: bytes
    Age: 326121
    Cache-Control: max-age=604800
    Content-Type: text/html; charset=UTF-8
    Date: Tue, 17 Nov 2020 02:47:38 GMT
    Etag: "3147526947"
    Expires: Tue, 24 Nov 2020 02:47:38 GMT
    Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
    Server: ECS (dcb/7EC9)
    X-Cache: HIT
    Content-Length: 1256
    
    It's defined in RFC 7231:
    The HEAD method is identical to GET except that the server MUST NOT send a message body in the response (i.e., the response terminates at the end of the header section). The server SHOULD send the same header fields in response to a HEAD request as it would have sent if the request had been a GET, except that the payload header fields MAY be omitted.

    Unfortunately, HEAD is a trap. When you are trying to debug strange server behavior, it is much safer to send GET requests and throw away the body (ex, ex). Not only is "SHOULD" just a recommendation, but even if this were a "MUST" you could bet some servers would mishandle it. Counterfactuals are hard!

    While differences are rare, always debugging by requesting the body like a normal client would, and then discarding it, means one fewer way that your debug request differs from a real one:

    $ curl -sS -D- -o/dev/null http://www.example.com
    HTTP/1.1 200 OK
    Accept-Ranges: bytes
    Age: 326124
    Cache-Control: max-age=604800
    Content-Type: text/html; charset=UTF-8
    Date: Tue, 17 Nov 2020 02:47:41 GMT
    Etag: "3147526947"
    Expires: Tue, 24 Nov 2020 02:47:41 GMT
    Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
    Server: ECS (dcb/7EC9)
    Vary: Accept-Encoding
    X-Cache: HIT
    Content-Length: 1256
    

    Going farther in the same direction, it's even better to start with "Copy as cURL":

    And then add the -sS -D- -o/dev/null to get the headers if that's all you want.

    Comment via: facebook, lesswrong

    Recent posts on blogs I like:

    Streaming the Biden Infrastructure Plan

    I streamed my thoughts about the Biden infrastructure plan, and unlike previous streams, I uploaded this to YouTube. I go into more details (and more tangents) on video, but, some key points: Out of the nearly $600 billion in the current proposal that is …

    via Pedestrian Observations April 11, 2021

    Collections: Clothing, How Did They Make it? Part IVb: Cloth Money

    This is the second half of the fourth part of our four part (I, II, III, IVa) look at the production of textiles, particularly wool and linen, in the pre-modern world. Last time, we looked at commercial textile workers and the finishing processes for text…

    via A Collection of Unmitigated Pedantry April 9, 2021

    Notes from “Don’t Shoot the Dog”

    I just finished Karen Pryor’s “Don’t Shoot the Dog: the New Art of Teaching and Training.” Partly because a friend points out that it’s not on Audible and therefore she can’t possibly read it, here are the notes I took and some thoughts. It’s a quick, eas…

    via The whole sky April 2, 2021

    more     (via openring)


  • Posts
  • RSS
  • ◂◂RSS
  • Contact