haproxy/include/common/hpack-dec.h

40 lines
1.5 KiB
C
Raw Normal View History

/*
* HPACK decompressor (RFC7541)
*
* Copyright (C) 2014-2017 Willy Tarreau <willy@haproxy.org>
* Copyright (C) 2017 HAProxy Technologies
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _COMMON_HPACK_DEC_H
#define _COMMON_HPACK_DEC_H
#include <haproxy/api.h>
MEDIUM: h2: change hpack_decode_headers() to only provide a list of headers The current H2 to H1 protocol conversion presents some issues which will require to perform some processing on certain headers before writing them so it's not possible to convert HPACK to H1 on the fly. This commit modifies the headers decoding so that it now works in two phases : hpack_decode_headers() only decodes the HPACK stream in the HEADERS frame and puts the result into a list. Headers which require storage (huffman-compressed or from the dynamic table) are stored in a chunk allocated by the H2 demuxer. Then once the headers are properly decoded into this list, h2_make_h1_request() is called with this list to produce the HTTP/1.1 request into the destination buffer. The list necessarily enforces a limit. Here we use 2*MAX_HTTP_HDR, which means that we can have as many individual cookies as we have regular headers if a client decides to break their cookies into multiple values. This seams reasonable and will allow the H1 parser to decide whether it's too much or not. Thus the output stream is not produced on the fly anymore and this will permit to deal with certain corner cases like reparing the Cookie header (which for now is not done). In order to limit header duplication and parsing, the known pseudo headers continue to be passed by their index : the name element in the list then has a NULL pointer and the value is the pseudo header's index. Given that these ones represent about half of the incoming requests and need to be found quickly, it maintains an acceptable level of performance. The code was significantly reduced by doing this because the orignal code had to deal with HPACK and H1 combinations (eg: index vs not indexed, etc) and now the HPACK decoding is totally focused on the decompression, and the H1 encoding doesn't have to deal with the issue of wrapping input for example. One bug was addressed here (though it couldn't happen at the moment). The H2 demuxer used to detect a failure to write the request into the H1 buffer and would then detect if the output buffer wraps, realign it and try again. The problem by doing so was that the HPACK context was already modified and not rewindable. Thus the size check is now performed first and a failure is reported if it doesn't fit.
2017-11-21 19:03:02 +00:00
#include <common/chunk.h>
#include <common/hpack-tbl.h>
MEDIUM: h2: change hpack_decode_headers() to only provide a list of headers The current H2 to H1 protocol conversion presents some issues which will require to perform some processing on certain headers before writing them so it's not possible to convert HPACK to H1 on the fly. This commit modifies the headers decoding so that it now works in two phases : hpack_decode_headers() only decodes the HPACK stream in the HEADERS frame and puts the result into a list. Headers which require storage (huffman-compressed or from the dynamic table) are stored in a chunk allocated by the H2 demuxer. Then once the headers are properly decoded into this list, h2_make_h1_request() is called with this list to produce the HTTP/1.1 request into the destination buffer. The list necessarily enforces a limit. Here we use 2*MAX_HTTP_HDR, which means that we can have as many individual cookies as we have regular headers if a client decides to break their cookies into multiple values. This seams reasonable and will allow the H1 parser to decide whether it's too much or not. Thus the output stream is not produced on the fly anymore and this will permit to deal with certain corner cases like reparing the Cookie header (which for now is not done). In order to limit header duplication and parsing, the known pseudo headers continue to be passed by their index : the name element in the list then has a NULL pointer and the value is the pseudo header's index. Given that these ones represent about half of the incoming requests and need to be found quickly, it maintains an acceptable level of performance. The code was significantly reduced by doing this because the orignal code had to deal with HPACK and H1 combinations (eg: index vs not indexed, etc) and now the HPACK decoding is totally focused on the decompression, and the H1 encoding doesn't have to deal with the issue of wrapping input for example. One bug was addressed here (though it couldn't happen at the moment). The H2 demuxer used to detect a failure to write the request into the H1 buffer and would then detect if the output buffer wraps, realign it and try again. The problem by doing so was that the HPACK context was already modified and not rewindable. Thus the size check is now performed first and a failure is reported if it doesn't fit.
2017-11-21 19:03:02 +00:00
int hpack_decode_frame(struct hpack_dht *dht, const uint8_t *raw, uint32_t len,
struct http_hdr *list, int list_size,
struct buffer *tmp);
#endif /* _COMMON_HPACK_DEC_H */