2014-09-21 11:28:06 +02:00
|
|
|
/*
|
|
|
|
* nghttp2 - HTTP/2 C Library
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 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 ASIO_HTTP2_H
|
|
|
|
#define ASIO_HTTP2_H
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <functional>
|
2015-03-01 02:02:49 +01:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include <boost/system/error_code.hpp>
|
|
|
|
#include <boost/asio.hpp>
|
2015-03-03 18:43:13 +01:00
|
|
|
#include <boost/asio/ssl.hpp>
|
2015-03-01 02:02:49 +01:00
|
|
|
|
|
|
|
#include <nghttp2/nghttp2.h>
|
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
namespace system {
|
|
|
|
|
|
|
|
template <> struct is_error_code_enum<nghttp2_error> {
|
|
|
|
BOOST_STATIC_CONSTANT(bool, value = true);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace system
|
|
|
|
} // namespace boost
|
2014-09-21 11:28:06 +02:00
|
|
|
|
|
|
|
namespace nghttp2 {
|
|
|
|
|
|
|
|
namespace asio_http2 {
|
|
|
|
|
2015-03-01 02:02:49 +01:00
|
|
|
struct header_value {
|
|
|
|
std::string value;
|
|
|
|
bool sensitive;
|
|
|
|
};
|
|
|
|
|
|
|
|
using header_map = std::multimap<std::string, header_value>;
|
|
|
|
|
|
|
|
const boost::system::error_category &nghttp2_category() noexcept;
|
|
|
|
|
2015-03-03 16:59:22 +01:00
|
|
|
struct uri_ref {
|
|
|
|
std::string scheme;
|
|
|
|
std::string host;
|
|
|
|
// percent-decoded form
|
|
|
|
std::string path;
|
2015-03-04 13:31:27 +01:00
|
|
|
std::string raw_path;
|
2015-03-03 16:59:22 +01:00
|
|
|
std::string raw_query;
|
|
|
|
std::string fragment;
|
|
|
|
};
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
typedef std::function<void(const uint8_t *, std::size_t)> data_cb;
|
2014-09-21 11:28:06 +02:00
|
|
|
typedef std::function<void(void)> void_cb;
|
2015-03-03 16:23:17 +01:00
|
|
|
typedef std::function<void(const boost::system::error_code &ec)> error_cb;
|
2015-03-01 02:02:49 +01:00
|
|
|
typedef std::function<void(uint32_t)> close_cb;
|
2014-09-21 11:28:06 +02:00
|
|
|
|
2015-03-04 14:45:29 +01:00
|
|
|
// Callback function to generate response body. TBD
|
|
|
|
typedef std::function<
|
|
|
|
ssize_t(uint8_t *buf, std::size_t len, uint32_t *data_flags)> read_cb;
|
2014-09-21 11:28:06 +02:00
|
|
|
|
|
|
|
// Convenient function to create function to read file denoted by
|
|
|
|
// |path|. This can be passed to response::end().
|
2014-11-27 15:39:04 +01:00
|
|
|
read_cb file_reader(const std::string &path);
|
2014-09-21 11:28:06 +02:00
|
|
|
|
2014-09-24 16:05:13 +02:00
|
|
|
// Like file_reader(const std::string&), but it takes opened file
|
|
|
|
// descriptor. The passed descriptor will be closed when returned
|
|
|
|
// function object is destroyed.
|
|
|
|
read_cb file_reader_from_fd(int fd);
|
|
|
|
|
|
|
|
// Validates path so that it does not contain directory traversal
|
|
|
|
// vector. Returns true if path is safe. The |path| must start with
|
|
|
|
// "/" otherwise returns false. This function should be called after
|
|
|
|
// percent-decode was performed.
|
2014-11-27 15:39:04 +01:00
|
|
|
bool check_path(const std::string &path);
|
2014-09-24 16:05:13 +02:00
|
|
|
|
|
|
|
// Performs percent-decode against string |s|.
|
2014-11-27 15:39:04 +01:00
|
|
|
std::string percent_decode(const std::string &s);
|
2014-09-24 16:05:13 +02:00
|
|
|
|
|
|
|
// Returns HTTP date representation of current posix time |t|.
|
2014-10-27 17:01:48 +01:00
|
|
|
std::string http_date(int64_t t);
|
2014-09-24 16:05:13 +02:00
|
|
|
|
2014-09-21 11:28:06 +02:00
|
|
|
} // namespace asio_http2
|
|
|
|
|
|
|
|
} // namespace nghttp2
|
|
|
|
|
|
|
|
#endif // ASIO_HTTP2_H
|