2013-08-27 19:47:22 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2013-08-27 19:47:22 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* 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 HTTP2_H
|
|
|
|
#define HTTP2_H
|
|
|
|
|
|
|
|
#include "nghttp2_config.h"
|
|
|
|
|
2013-11-17 15:52:19 +01:00
|
|
|
#include <cstdio>
|
2013-12-08 14:31:43 +01:00
|
|
|
#include <cstring>
|
2013-08-27 19:47:22 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2015-02-05 15:06:56 +01:00
|
|
|
#include <array>
|
2013-08-27 19:47:22 +02:00
|
|
|
|
|
|
|
#include <nghttp2/nghttp2.h>
|
|
|
|
|
|
|
|
#include "http-parser/http_parser.h"
|
|
|
|
|
2015-07-09 19:52:11 +02:00
|
|
|
#include "util.h"
|
2015-09-11 16:07:00 +02:00
|
|
|
#include "memchunk.h"
|
2016-03-09 13:15:32 +01:00
|
|
|
#include "template.h"
|
2016-03-10 14:42:07 +01:00
|
|
|
#include "allocator.h"
|
2015-07-09 19:52:11 +02:00
|
|
|
|
2013-08-27 19:47:22 +02:00
|
|
|
namespace nghttp2 {
|
|
|
|
|
2014-04-03 04:22:11 +02:00
|
|
|
struct Header {
|
2015-02-08 06:07:01 +01:00
|
|
|
Header(std::string name, std::string value, bool no_index = false,
|
2016-02-21 08:44:00 +01:00
|
|
|
int32_t token = -1)
|
2016-01-27 13:14:07 +01:00
|
|
|
: name(std::move(name)),
|
|
|
|
value(std::move(value)),
|
|
|
|
token(token),
|
2015-02-08 06:07:01 +01:00
|
|
|
no_index(no_index) {}
|
2014-11-27 15:39:04 +01:00
|
|
|
|
2015-02-08 06:07:01 +01:00
|
|
|
Header() : token(-1), no_index(false) {}
|
2014-11-27 15:39:04 +01:00
|
|
|
|
|
|
|
bool operator==(const Header &other) const {
|
2014-04-03 04:22:11 +02:00
|
|
|
return name == other.name && value == other.value;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
bool operator<(const Header &rhs) const {
|
2014-04-03 04:22:11 +02:00
|
|
|
return name < rhs.name || (name == rhs.name && value < rhs.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
std::string value;
|
2016-02-21 08:44:00 +01:00
|
|
|
int32_t token;
|
2014-04-03 04:22:11 +02:00
|
|
|
bool no_index;
|
|
|
|
};
|
|
|
|
|
2016-03-09 13:15:32 +01:00
|
|
|
struct HeaderRef {
|
|
|
|
HeaderRef(const StringRef &name, const StringRef &value,
|
|
|
|
bool no_index = false, int32_t token = -1)
|
|
|
|
: name(name), value(value), token(token), no_index(no_index) {}
|
|
|
|
|
|
|
|
HeaderRef() : token(-1), no_index(false) {}
|
|
|
|
|
|
|
|
bool operator==(const HeaderRef &other) const {
|
|
|
|
return name == other.name && value == other.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const HeaderRef &rhs) const {
|
|
|
|
return name < rhs.name || (name == rhs.name && value < rhs.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef name;
|
|
|
|
StringRef value;
|
|
|
|
int32_t token;
|
|
|
|
bool no_index;
|
|
|
|
};
|
|
|
|
|
2015-06-21 12:37:50 +02:00
|
|
|
using Headers = std::vector<Header>;
|
2016-03-09 13:15:32 +01:00
|
|
|
using HeaderRefs = std::vector<HeaderRef>;
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2013-08-27 19:47:22 +02:00
|
|
|
namespace http2 {
|
|
|
|
|
2016-11-03 18:18:42 +01:00
|
|
|
// Returns reason-phrase for given |status code|. If there is no
|
|
|
|
// known reason-phrase for the given code, returns empty string.
|
|
|
|
StringRef get_reason_phrase(unsigned int status_code);
|
2013-08-27 19:47:22 +02:00
|
|
|
|
2016-03-19 15:41:21 +01:00
|
|
|
// Returns string version of |status_code|. (e.g., "404")
|
|
|
|
StringRef stringify_status(BlockAllocator &balloc, unsigned int status_code);
|
2015-11-05 14:48:54 +01:00
|
|
|
|
2017-02-12 15:27:38 +01:00
|
|
|
void capitalize(DefaultMemchunks *buf, const StringRef &s);
|
|
|
|
|
2014-01-16 18:16:53 +01:00
|
|
|
// Returns true if |value| is LWS
|
|
|
|
bool lws(const char *value);
|
2013-09-11 16:24:32 +02:00
|
|
|
|
2013-08-27 19:47:22 +02:00
|
|
|
// Copies the |field| component value from |u| and |url| to the
|
|
|
|
// |dest|. If |u| does not have |field|, then this function does
|
|
|
|
// nothing.
|
2014-11-27 15:39:04 +01:00
|
|
|
void copy_url_component(std::string &dest, const http_parser_url *u, int field,
|
|
|
|
const char *url);
|
2013-08-27 19:47:22 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
Headers::value_type to_header(const uint8_t *name, size_t namelen,
|
2014-04-03 04:22:11 +02:00
|
|
|
const uint8_t *value, size_t valuelen,
|
2016-02-21 08:44:00 +01:00
|
|
|
bool no_index, int32_t token);
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2014-07-12 11:55:08 +02:00
|
|
|
// Add name/value pairs to |nva|. If |no_index| is true, this
|
|
|
|
// name/value pair won't be indexed when it is forwarded to the next
|
2014-12-15 15:04:45 +01:00
|
|
|
// hop. This function strips white spaces around |value|.
|
2014-11-27 15:39:04 +01:00
|
|
|
void add_header(Headers &nva, const uint8_t *name, size_t namelen,
|
2015-02-08 06:07:01 +01:00
|
|
|
const uint8_t *value, size_t valuelen, bool no_index,
|
2016-02-21 08:44:00 +01:00
|
|
|
int32_t token);
|
2013-11-13 15:56:02 +01:00
|
|
|
|
2015-01-04 15:22:39 +01:00
|
|
|
// Returns pointer to the entry in |nva| which has name |name|. If
|
|
|
|
// more than one entries which have the name |name|, last occurrence
|
|
|
|
// in |nva| is returned. If no such entry exist, returns nullptr.
|
2014-11-27 15:39:04 +01:00
|
|
|
const Headers::value_type *get_header(const Headers &nva, const char *name);
|
2013-08-27 19:47:22 +02:00
|
|
|
|
2014-12-15 15:14:07 +01:00
|
|
|
// Returns true if the value of |nv| is not empty.
|
2016-03-09 13:15:32 +01:00
|
|
|
bool non_empty_value(const HeaderRefs::value_type *nv);
|
2013-10-25 14:50:56 +02:00
|
|
|
|
2013-11-28 13:36:04 +01:00
|
|
|
// Creates nghttp2_nv using |name| and |value| and returns it. The
|
|
|
|
// returned value only references the data pointer to name.c_str() and
|
2014-04-03 04:22:11 +02:00
|
|
|
// value.c_str(). If |no_index| is true, nghttp2_nv flags member has
|
|
|
|
// NGHTTP2_NV_FLAG_NO_INDEX flag set.
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_nv make_nv(const std::string &name, const std::string &value,
|
2014-04-26 07:56:08 +02:00
|
|
|
bool no_index = false);
|
2013-11-28 13:36:04 +01:00
|
|
|
|
2016-03-09 13:15:32 +01:00
|
|
|
nghttp2_nv make_nv(const StringRef &name, const StringRef &value,
|
|
|
|
bool no_index = false);
|
|
|
|
|
2015-11-05 14:48:54 +01:00
|
|
|
nghttp2_nv make_nv_nocopy(const std::string &name, const std::string &value,
|
|
|
|
bool no_index = false);
|
|
|
|
|
2016-03-09 13:15:32 +01:00
|
|
|
nghttp2_nv make_nv_nocopy(const StringRef &name, const StringRef &value,
|
|
|
|
bool no_index = false);
|
|
|
|
|
2013-12-08 14:31:43 +01:00
|
|
|
// Create nghttp2_nv from string literal |name| and |value|.
|
2014-11-27 15:39:04 +01:00
|
|
|
template <size_t N, size_t M>
|
2016-10-15 11:36:04 +02:00
|
|
|
constexpr nghttp2_nv make_nv_ll(const char (&name)[N], const char (&value)[M]) {
|
2014-11-27 15:39:04 +01:00
|
|
|
return {(uint8_t *)name, (uint8_t *)value, N - 1, M - 1,
|
2015-11-05 14:48:54 +01:00
|
|
|
NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE};
|
2013-12-08 14:31:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create nghttp2_nv from string literal |name| and c-string |value|.
|
2014-11-27 15:39:04 +01:00
|
|
|
template <size_t N>
|
2016-10-15 11:36:04 +02:00
|
|
|
nghttp2_nv make_nv_lc(const char (&name)[N], const char *value) {
|
2014-11-27 15:39:04 +01:00
|
|
|
return {(uint8_t *)name, (uint8_t *)value, N - 1, strlen(value),
|
2015-11-05 14:48:54 +01:00
|
|
|
NGHTTP2_NV_FLAG_NO_COPY_NAME};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t N>
|
2016-10-15 11:36:04 +02:00
|
|
|
nghttp2_nv make_nv_lc_nocopy(const char (&name)[N], const char *value) {
|
2015-11-05 14:48:54 +01:00
|
|
|
return {(uint8_t *)name, (uint8_t *)value, N - 1, strlen(value),
|
|
|
|
NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE};
|
2013-12-08 14:31:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create nghttp2_nv from string literal |name| and std::string
|
|
|
|
// |value|.
|
2014-11-27 15:39:04 +01:00
|
|
|
template <size_t N>
|
2016-10-15 11:36:04 +02:00
|
|
|
nghttp2_nv make_nv_ls(const char (&name)[N], const std::string &value) {
|
2014-11-27 15:39:04 +01:00
|
|
|
return {(uint8_t *)name, (uint8_t *)value.c_str(), N - 1, value.size(),
|
2015-11-05 14:48:54 +01:00
|
|
|
NGHTTP2_NV_FLAG_NO_COPY_NAME};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t N>
|
2016-10-15 11:36:04 +02:00
|
|
|
nghttp2_nv make_nv_ls_nocopy(const char (&name)[N], const std::string &value) {
|
2015-11-05 14:48:54 +01:00
|
|
|
return {(uint8_t *)name, (uint8_t *)value.c_str(), N - 1, value.size(),
|
|
|
|
NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE};
|
2013-12-08 14:31:43 +01:00
|
|
|
}
|
|
|
|
|
2016-01-16 16:52:41 +01:00
|
|
|
template <size_t N>
|
2016-10-15 11:36:04 +02:00
|
|
|
nghttp2_nv make_nv_ls_nocopy(const char (&name)[N], const StringRef &value) {
|
2016-01-16 16:52:41 +01:00
|
|
|
return {(uint8_t *)name, (uint8_t *)value.c_str(), N - 1, value.size(),
|
|
|
|
NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE};
|
|
|
|
}
|
|
|
|
|
2015-02-08 06:07:01 +01:00
|
|
|
// Appends headers in |headers| to |nv|. |headers| must be indexed
|
|
|
|
// before this call (its element's token field is assigned). Certain
|
|
|
|
// headers, including disallowed headers in HTTP/2 spec and headers
|
|
|
|
// which require special handling (i.e. via), are not copied.
|
2016-03-09 13:15:32 +01:00
|
|
|
void copy_headers_to_nva(std::vector<nghttp2_nv> &nva,
|
|
|
|
const HeaderRefs &headers);
|
2013-08-27 19:47:22 +02:00
|
|
|
|
2015-11-05 14:48:54 +01:00
|
|
|
// Just like copy_headers_to_nva(), but this adds
|
|
|
|
// NGHTTP2_NV_FLAG_NO_COPY_NAME and NGHTTP2_NV_FLAG_NO_COPY_VALUE.
|
|
|
|
void copy_headers_to_nva_nocopy(std::vector<nghttp2_nv> &nva,
|
2016-03-09 13:15:32 +01:00
|
|
|
const HeaderRefs &headers);
|
2015-11-05 14:48:54 +01:00
|
|
|
|
2015-09-11 16:07:00 +02:00
|
|
|
// Appends HTTP/1.1 style header lines to |buf| from headers in
|
2015-02-08 06:07:01 +01:00
|
|
|
// |headers|. |headers| must be indexed before this call (its
|
|
|
|
// element's token field is assigned). Certain headers, which
|
|
|
|
// requires special handling (i.e. via and cookie), are not appended.
|
2015-09-11 16:07:00 +02:00
|
|
|
void build_http1_headers_from_headers(DefaultMemchunks *buf,
|
2016-03-09 13:15:32 +01:00
|
|
|
const HeaderRefs &headers);
|
2013-08-27 19:47:22 +02:00
|
|
|
|
2013-10-29 16:51:01 +01:00
|
|
|
// Return positive window_size_increment if WINDOW_UPDATE should be
|
|
|
|
// sent for the stream |stream_id|. If |stream_id| == 0, this function
|
|
|
|
// determines the necessity of the WINDOW_UPDATE for a connection.
|
|
|
|
//
|
|
|
|
// If the function determines WINDOW_UPDATE is not necessary at the
|
|
|
|
// moment, it returns -1.
|
|
|
|
int32_t determine_window_update_transmission(nghttp2_session *session,
|
|
|
|
int32_t stream_id);
|
|
|
|
|
2013-11-17 15:52:19 +01:00
|
|
|
// Dumps name/value pairs in |nv| to |out|. The |nv| must be
|
|
|
|
// terminated by nullptr.
|
|
|
|
void dump_nv(FILE *out, const char **nv);
|
|
|
|
|
|
|
|
// Dumps name/value pairs in |nva| to |out|.
|
|
|
|
void dump_nv(FILE *out, const nghttp2_nv *nva, size_t nvlen);
|
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
// Dumps name/value pairs in |nva| to |out|.
|
2014-11-27 15:39:04 +01:00
|
|
|
void dump_nv(FILE *out, const Headers &nva);
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2016-03-09 13:15:32 +01:00
|
|
|
void dump_nv(FILE *out, const HeaderRefs &nva);
|
|
|
|
|
2016-12-03 06:57:48 +01:00
|
|
|
// Ereases header in |hd|.
|
|
|
|
void erase_header(HeaderRef *hd);
|
|
|
|
|
2013-12-21 09:49:31 +01:00
|
|
|
// Rewrites redirection URI which usually appears in location header
|
|
|
|
// field. The |uri| is the URI in the location header field. The |u|
|
2015-02-08 11:41:45 +01:00
|
|
|
// stores the result of parsed |uri|. The |request_authority| is the
|
|
|
|
// host or :authority header field value in the request. The
|
2013-12-21 09:49:31 +01:00
|
|
|
// |upstream_scheme| is either "https" or "http" in the upstream
|
2015-02-08 11:41:45 +01:00
|
|
|
// interface. Rewrite is done only if location header field value
|
|
|
|
// contains |match_host| as host excluding port. The |match_host| and
|
|
|
|
// |request_authority| could be different. If |request_authority| is
|
|
|
|
// empty, strip authority.
|
2013-12-21 09:49:31 +01:00
|
|
|
//
|
|
|
|
// This function returns the new rewritten URI on success. If the
|
|
|
|
// location URI is not subject to the rewrite, this function returns
|
|
|
|
// emtpy string.
|
2016-03-10 14:42:07 +01:00
|
|
|
StringRef rewrite_location_uri(BlockAllocator &balloc, const StringRef &uri,
|
|
|
|
const http_parser_url &u,
|
|
|
|
const StringRef &match_host,
|
|
|
|
const StringRef &request_authority,
|
|
|
|
const StringRef &upstream_scheme);
|
2013-12-21 09:49:31 +01:00
|
|
|
|
2014-02-01 11:31:50 +01:00
|
|
|
// Checks the header name/value pair using nghttp2_check_header_name()
|
|
|
|
// and nghttp2_check_header_value(). If both function returns nonzero,
|
|
|
|
// this function returns nonzero.
|
2014-11-27 15:39:04 +01:00
|
|
|
int check_nv(const uint8_t *name, size_t namelen, const uint8_t *value,
|
|
|
|
size_t valuelen);
|
2014-01-16 18:16:53 +01:00
|
|
|
|
2014-08-08 16:03:12 +02:00
|
|
|
// Returns parsed HTTP status code. Returns -1 on failure.
|
2016-03-09 13:15:32 +01:00
|
|
|
int parse_http_status_code(const StringRef &src);
|
2014-08-08 16:03:12 +02:00
|
|
|
|
2015-01-04 15:22:39 +01:00
|
|
|
// Header fields to be indexed, except HD_MAXIDX which is convenient
|
|
|
|
// member to get maximum value.
|
2016-01-15 15:04:58 +01:00
|
|
|
//
|
|
|
|
// generated by genheaderfunc.py
|
2015-01-02 16:12:26 +01:00
|
|
|
enum {
|
2015-01-04 15:22:39 +01:00
|
|
|
HD__AUTHORITY,
|
|
|
|
HD__HOST,
|
|
|
|
HD__METHOD,
|
|
|
|
HD__PATH,
|
|
|
|
HD__SCHEME,
|
|
|
|
HD__STATUS,
|
2015-02-08 06:23:22 +01:00
|
|
|
HD_ACCEPT_ENCODING,
|
|
|
|
HD_ACCEPT_LANGUAGE,
|
2015-01-04 15:22:39 +01:00
|
|
|
HD_ALT_SVC,
|
2015-02-08 06:23:22 +01:00
|
|
|
HD_CACHE_CONTROL,
|
2015-01-02 16:12:26 +01:00
|
|
|
HD_CONNECTION,
|
2015-01-04 15:22:39 +01:00
|
|
|
HD_CONTENT_LENGTH,
|
2016-01-20 03:16:49 +01:00
|
|
|
HD_CONTENT_TYPE,
|
2015-01-04 15:22:39 +01:00
|
|
|
HD_COOKIE,
|
2015-09-07 16:11:23 +02:00
|
|
|
HD_DATE,
|
2015-01-02 16:12:26 +01:00
|
|
|
HD_EXPECT,
|
2016-01-15 15:04:58 +01:00
|
|
|
HD_FORWARDED,
|
2015-01-02 16:12:26 +01:00
|
|
|
HD_HOST,
|
2015-01-04 15:22:39 +01:00
|
|
|
HD_HTTP2_SETTINGS,
|
2015-01-02 16:12:26 +01:00
|
|
|
HD_IF_MODIFIED_SINCE,
|
|
|
|
HD_KEEP_ALIVE,
|
2015-02-07 08:09:49 +01:00
|
|
|
HD_LINK,
|
2015-01-04 15:22:39 +01:00
|
|
|
HD_LOCATION,
|
2015-01-02 16:12:26 +01:00
|
|
|
HD_PROXY_CONNECTION,
|
2015-01-04 15:22:39 +01:00
|
|
|
HD_SERVER,
|
2015-01-02 16:12:26 +01:00
|
|
|
HD_TE,
|
2015-01-14 13:33:22 +01:00
|
|
|
HD_TRAILER,
|
2015-01-02 16:12:26 +01:00
|
|
|
HD_TRANSFER_ENCODING,
|
|
|
|
HD_UPGRADE,
|
2015-02-08 06:23:22 +01:00
|
|
|
HD_USER_AGENT,
|
2015-01-04 15:22:39 +01:00
|
|
|
HD_VIA,
|
|
|
|
HD_X_FORWARDED_FOR,
|
|
|
|
HD_X_FORWARDED_PROTO,
|
2015-01-02 16:12:26 +01:00
|
|
|
HD_MAXIDX,
|
|
|
|
};
|
|
|
|
|
2015-02-08 05:05:37 +01:00
|
|
|
using HeaderIndex = std::array<int16_t, HD_MAXIDX>;
|
2015-02-05 15:06:56 +01:00
|
|
|
|
2015-01-04 15:22:39 +01:00
|
|
|
// Looks up header token for header name |name| of length |namelen|.
|
|
|
|
// Only headers we are interested in are tokenized. If header name
|
|
|
|
// cannot be tokenized, returns -1.
|
|
|
|
int lookup_token(const uint8_t *name, size_t namelen);
|
2016-03-09 13:15:32 +01:00
|
|
|
int lookup_token(const StringRef &name);
|
2015-01-04 15:22:39 +01:00
|
|
|
|
2015-01-02 16:12:26 +01:00
|
|
|
// Initializes |hdidx|, header index. The |hdidx| must point to the
|
|
|
|
// array containing at least HD_MAXIDX elements.
|
2015-02-05 15:06:56 +01:00
|
|
|
void init_hdidx(HeaderIndex &hdidx);
|
2015-01-04 15:22:39 +01:00
|
|
|
// Indexes header |token| using index |idx|.
|
2016-02-21 08:44:00 +01:00
|
|
|
void index_header(HeaderIndex &hdidx, int32_t token, size_t idx);
|
2015-01-04 15:22:39 +01:00
|
|
|
|
|
|
|
// Returns header denoted by |token| using index |hdidx|.
|
2016-02-21 08:44:00 +01:00
|
|
|
const Headers::value_type *get_header(const HeaderIndex &hdidx, int32_t token,
|
2015-01-02 16:12:26 +01:00
|
|
|
const Headers &nva);
|
|
|
|
|
2016-02-21 08:44:00 +01:00
|
|
|
Headers::value_type *get_header(const HeaderIndex &hdidx, int32_t token,
|
2015-09-02 17:40:14 +02:00
|
|
|
Headers &nva);
|
|
|
|
|
2015-02-07 08:09:49 +01:00
|
|
|
struct LinkHeader {
|
2016-03-03 15:31:44 +01:00
|
|
|
// The region of URI. This might not be NULL-terminated.
|
|
|
|
StringRef uri;
|
2015-02-07 08:09:49 +01:00
|
|
|
};
|
|
|
|
|
2016-03-25 15:51:42 +01:00
|
|
|
// Returns next URI-reference in Link header field value |src|. If no
|
|
|
|
// URI-reference found after searching all input, returned uri field
|
|
|
|
// is empty. This imply that empty URI-reference is ignored during
|
|
|
|
// parsing.
|
|
|
|
std::vector<LinkHeader> parse_link_header(const StringRef &src);
|
2015-02-07 08:09:49 +01:00
|
|
|
|
2016-03-03 16:26:59 +01:00
|
|
|
// Constructs path by combining base path |base_path| with another
|
|
|
|
// path |rel_path|. The base path and another path can have optional
|
2015-03-03 18:48:20 +01:00
|
|
|
// query component. This function assumes |base_path| is normalized.
|
|
|
|
// In other words, it does not contain ".." or "." path components
|
|
|
|
// and starts with "/" if it is not empty.
|
2016-03-03 16:26:59 +01:00
|
|
|
std::string path_join(const StringRef &base, const StringRef &base_query,
|
|
|
|
const StringRef &rel_path, const StringRef &rel_query);
|
2015-02-07 08:09:49 +01:00
|
|
|
|
2016-03-10 14:42:07 +01:00
|
|
|
StringRef path_join(BlockAllocator &balloc, const StringRef &base_path,
|
|
|
|
const StringRef &base_query, const StringRef &rel_path,
|
|
|
|
const StringRef &rel_query);
|
|
|
|
|
2015-03-06 13:36:40 +01:00
|
|
|
// true if response has body, taking into account the request method
|
|
|
|
// and status code.
|
|
|
|
bool expect_response_body(const std::string &method, int status_code);
|
2015-06-09 16:15:02 +02:00
|
|
|
bool expect_response_body(int method_token, int status_code);
|
2015-03-06 13:36:40 +01:00
|
|
|
|
|
|
|
// true if response has body, taking into account status code only.
|
|
|
|
bool expect_response_body(int status_code);
|
|
|
|
|
2015-06-09 16:15:02 +02:00
|
|
|
// Looks up method token for method name |name| of length |namelen|.
|
|
|
|
// Only methods defined in http-parser/http-parser.h (http_method) are
|
|
|
|
// tokenized. If method name cannot be tokenized, returns -1.
|
|
|
|
int lookup_method_token(const uint8_t *name, size_t namelen);
|
2016-03-09 13:15:32 +01:00
|
|
|
int lookup_method_token(const StringRef &name);
|
2015-06-09 16:15:02 +02:00
|
|
|
|
2016-02-28 13:35:26 +01:00
|
|
|
// Returns string representation of |method_token|. This is wrapper
|
|
|
|
// function over http_method_str from http-parser. If |method_token|
|
|
|
|
// is not known to http-parser, "<unknown>" is returned. The returned
|
|
|
|
// StringRef is guaranteed to be NULL-terminated.
|
|
|
|
StringRef to_method_string(int method_token);
|
2015-06-09 16:15:02 +02:00
|
|
|
|
2016-03-10 14:42:07 +01:00
|
|
|
StringRef normalize_path(BlockAllocator &balloc, const StringRef &path,
|
|
|
|
const StringRef &query);
|
|
|
|
|
2016-03-10 15:50:04 +01:00
|
|
|
std::string normalize_path(const StringRef &path, const StringRef &query);
|
|
|
|
|
2016-03-10 14:42:07 +01:00
|
|
|
StringRef rewrite_clean_path(BlockAllocator &balloc, const StringRef &src);
|
|
|
|
|
2016-03-03 16:33:35 +01:00
|
|
|
// Returns path component of |uri|. The returned path does not
|
|
|
|
// include query component. This function returns empty string if it
|
|
|
|
// fails.
|
2016-03-10 14:42:07 +01:00
|
|
|
StringRef get_pure_path_component(const StringRef &uri);
|
2015-09-05 15:47:07 +02:00
|
|
|
|
2016-03-03 16:26:59 +01:00
|
|
|
// Deduces scheme, authority and path from given |uri|, and stores
|
|
|
|
// them in |scheme|, |authority|, and |path| respectively. If |uri|
|
|
|
|
// is relative path, path resolution takes place using path given in
|
|
|
|
// |base| of length |baselen|. This function returns 0 if it
|
|
|
|
// succeeds, or -1.
|
2016-03-10 14:42:07 +01:00
|
|
|
int construct_push_component(BlockAllocator &balloc, StringRef &scheme,
|
|
|
|
StringRef &authority, StringRef &path,
|
|
|
|
const StringRef &base, const StringRef &uri);
|
2015-09-05 15:47:07 +02:00
|
|
|
|
2016-03-10 16:50:27 +01:00
|
|
|
// Copies |src| and return its lower-cased version.
|
|
|
|
StringRef copy_lower(BlockAllocator &balloc, const StringRef &src);
|
|
|
|
|
2016-11-07 14:47:48 +01:00
|
|
|
// Returns true if te header field value |s| contains "trailers".
|
|
|
|
bool contains_trailers(const StringRef &s);
|
|
|
|
|
2013-08-27 19:47:22 +02:00
|
|
|
} // namespace http2
|
|
|
|
|
|
|
|
} // namespace nghttp2
|
|
|
|
|
|
|
|
#endif // HTTP2_H
|