HTTP/2 data compression
Asked Answered
A

1

14

I am trying to understand the way the HTTP/2 protocol compresses the Data field. I didn't find an algorithm in the rfc. I know its a binary protocol. I am looking for a way to get the binary protocol back into human readable content. I thought it is gzip like writen in the header but it isn't anyone has a source where i can look for the binary protocol refernce?

Frame 55: 151 bytes on wire (1208 bits), 151 bytes captured (1208 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst:00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1, Dst: 127.0.0.1
Transmission Control Protocol, Src Port: 443 (443), Dst Port: 55300 (55300), Seq: 1087, Ack: 1078, Len: 85
Secure Sockets Layer
HyperText Transfer Protocol 2
Stream: HEADERS, Stream ID: 13, Length 47
    Length: 47
    Type: HEADERS (1)
    Flags: 0x04
    0... .... .... .... .... .... .... .... = Reserved: 0x00000000
    .000 0000 0000 0000 0000 0000 0000 1101 = Stream Identifier: 13
    [Pad Length: 0]
    Header Block Fragment: 8854012a5a839bd9ab5f87497ca589d34d1f5c0333333861...
    [Header Length: 177]
    [Header Count: 6]
    Header: :status: 200
    Header: access-control-allow-origin: *
    Header: content-encoding: gzip
    Header: content-type: text/html
    Header: content-length: 338
    Header: date: Wed, 17 Aug 2016 15:14:25 GMT
    Padding: <MISSING>

    Frame 56: 442 bytes on wire (3536 bits), 442 bytes captured (3536 bits) on interface 0
  Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
  Internet Protocol Version 4, Src: 127.0.0.1, Dst: 127.0.0.1
  Transmission Control Protocol, Src Port: 443 (443), Dst Port: 55300 (55300), Seq: 1172, Ack: 1078, Len: 376
  Secure Sockets Layer
  HyperText Transfer Protocol 2
      Stream: DATA, Stream ID: 13, Length 338
          Length: 338
          Type: DATA (0)
          Flags: 0x01
          0... .... .... .... .... .... .... .... = Reserved: 0x00000000
          .000 0000 0000 0000 0000 0000 0000 1101 = Stream Identifier: 13
          [Pad Length: 0]
          Data: 1f8b080000096e8800ff9cd2416b1b311005e0b3ffc5eb9e...
          Padding: <MISSING>
Abrasion answered 17/8, 2016 at 15:34 Comment(3)
HTTP/2 doesn't add a new compression of the data payload, but the header. You obviously didn't look hard enough (.. or just search for "compression") in the RFC: tools.ietf.org/html/rfc7540#ref-COMPRESSION links to the HPACK document.Swarthy
i know how the header compression works i am interested in the this line Data: 1f8b080000096e8800ff9cd2416b1b311005e0b3ffc5eb9e... and this is not in the header so hpack isn't used there and it is not gzip it is some kind of binary format which i want to know how it worksAbrasion
1f8b08 are the initial bytes of gzip compression, so it is gzip. Furthermore, the response headers say content-encoding: gzip, so the DATA frame contains the gzipped response body.Orr
L
25

The response body of a HTTP/2 response is compressed (or not) exactly the same way as it works with HTTP/1: Accept-Encoding: in the request and Content-Encoding: in the response. HTTP/2 did nothing new with compression of the bodies, only with headers which weren't compressed at all in HTTP/1.

It can also be mentioned that HTTP/3 takes the exact same approach to compression as HTTP/2 does: the headers are compressed, the content according to the above.

No HTTP version does compressed upload content.

Luckin answered 18/8, 2016 at 18:23 Comment(3)
Indeed. There was a data compression proposal, but it was removed.Ferdy
Yes you can upload content in gzip, using a request header Content-Encoding: gzip. It's just not certain that the server supports it because the client never got a Accept-Encoding to ensure it. I have successfully uploaded gzipped body to onedrive apis for example, over http 1.1. I used a pre-compressed .gz file and it may have been with Content-Length instead of chunked, but still a success.Eldwon
I was hoping with the rise of GraphQLrequest bodies everywhere, HTTP/2 allowed automatic compression of request bodies as well.Landaulet

© 2022 - 2024 — McMap. All rights reserved.