Skip to content

Commit 18b6246

Browse files
committed
Add note about meaning and interpretation of Content-Type
1 parent cadaa66 commit 18b6246

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

http/get_compressed/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ If a server adopts this approach and a client does not specify any codecs in
8282
the `Accept` header, the server can fall back to checking `Accept-Encoding`
8383
header to pick a compression algorithm for the entire HTTP response stream.
8484

85+
To make debugging easier servers may include the chosen compression codec(s)
86+
in the `Content-Type` header of the response (quotes are optional):
87+
88+
Content-Type: application/vnd.apache.arrow.ipc; codecs=zstd
89+
90+
This is not necessary for correct decompression because the payload already
91+
contains information that tells the IPC reader how to decompress the buffers,
92+
but it can help developers understand what is going on.
93+
94+
When programatically checking if the `Content-Type` header contains a specific
95+
format, it is important to use a parser that can handle parameters or look
96+
only at the media type part of the header. This is not an exclusivity of the
97+
Arrow IPC format, but a general rule for all media types. For example,
98+
`application/json; charset=utf-8` should be match `application/json`.
99+
85100
## HTTP/1.1 Response Compression
86101

87102
HTTP/1.1 offers an elaborate way for clients to specify their preferred

http/get_compressed/python/client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def make_request(uri, compression):
3434
if compression.startswith("identity+"):
3535
# request IPC buffer compression instead of HTTP compression
3636
ipc_codec = compression.split("+")[1]
37-
headers["Accept"] = f'{ARROW_STREAM_FORMAT};codec="{ipc_codec}"'
37+
headers["Accept"] = f'{ARROW_STREAM_FORMAT};codecs="{ipc_codec}"'
3838
request = urllib.request.Request(uri, headers=headers)
3939

4040
response = urllib.request.urlopen(request)

http/get_compressed/python/server/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def do_GET(self):
524524
self.send_header(
525525
"Content-Type",
526526
(
527-
f"{ARROW_STREAM_FORMAT}; codec={compression[9:]}"
527+
f"{ARROW_STREAM_FORMAT}; codecs={compression[9:]}"
528528
if compression.startswith("identity+")
529529
else ARROW_STREAM_FORMAT
530530
),

http/get_simple/python/client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
response = urllib.request.urlopen('http://localhost:8008')
2727
content_type = response.headers['Content-Type']
28-
if content_type != ARROW_STREAM_FORMAT:
28+
if not content_type.startswith(ARROW_STREAM_FORMAT):
2929
raise ValueError(f"Expected {ARROW_STREAM_FORMAT}, got {content_type}")
3030

3131
batches = []

0 commit comments

Comments
 (0)