in http/get_compressed/python/server/server.py [0:0]
def pick_ipc_codec(accept_header, available, default):
"""
Pick the IPC stream codec according to the Accept header.
This is used when deciding which codec to use for compression of IPC buffer
streams. This is a feature of the Arrow IPC stream format and is different
from the HTTP content-coding used to compress the entire HTTP response.
This is how a client may specify the IPC buffer compression codecs it
accepts:
Accept: application/vnd.apache.arrow.stream; codecs="zstd, lz4"
Parameters
----------
accept_header : str|None
The value of the Accept header from an HTTP request.
available : list of str
The codecs that the server can provide in the order preferred by the
server. Example: ["zstd", "lz4"].
default : str|None
The codec to use if the client does not specify the ";codecs" parameter
in the Accept header.
Returns
-------
str|None
The codec that the server should use to compress the IPC buffer stream.
None if the client does not accept any of the available codecs
explicitly listed. ;codecs="" means no codecs are accepted.
If the client does not specify the codecs parameter, the default codec
is returned.
"""
did_specify_codecs = False
accepted_codecs = []
if accept_header is not None:
accepted = parse_header_value("Accept", accept_header)
for media_range, params in accepted:
if (
media_range == "*/*"
or media_range == "application/*"
or media_range == ARROW_STREAM_FORMAT
):
did_specify_codecs = "codecs" in params
codecs_str = params.get("codecs")
if codecs_str is None:
continue
for codec in codecs_str.split(","):
accepted_codecs.append(codec.strip())
for codec in available:
if codec in accepted_codecs:
return codec
return None if did_specify_codecs else default