2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2013 Tatsuhiro Tsujikawa
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "nghttp2_config.h"
31 #include <sys/types.h>
40 #include <openssl/ssl.h>
44 #include <nghttp2/nghttp2.h>
52 std::map<std::string, std::vector<std::string>> push;
55 std::string private_key_file;
56 std::string cert_file;
57 std::string dh_param_file;
58 ev_tstamp stream_read_timeout;
59 ev_tstamp stream_write_timeout;
60 nghttp2_option *session_option;
64 ssize_t header_table_size;
80 Http2Handler *handler;
87 http2::HeaderIndex hdidx;
88 Stream(Http2Handler *handler, int32_t stream_id);
96 Http2Handler(Sessions *sessions, int fd, SSL *ssl, int64_t session_id);
104 int verify_npn_result();
106 int submit_file_response(const std::string &status, Stream *stream,
107 time_t last_modified, off_t file_length,
108 nghttp2_data_provider *data_prd);
110 int submit_response(const std::string &status, int32_t stream_id,
111 nghttp2_data_provider *data_prd);
113 int submit_response(const std::string &status, int32_t stream_id,
114 const Headers &headers, nghttp2_data_provider *data_prd);
116 int submit_non_final_response(const std::string &status, int32_t stream_id);
118 int submit_push_promise(Stream *stream, const std::string &push_path);
120 int submit_rst_stream(Stream *stream, uint32_t error_code);
122 void add_stream(int32_t stream_id, std::unique_ptr<Stream> stream);
123 void remove_stream(int32_t stream_id);
124 Stream *get_stream(int32_t stream_id);
125 int64_t session_id() const;
126 Sessions *get_sessions() const;
127 const Config *get_config() const;
128 void remove_settings_timer();
129 void terminate_session(uint32_t error_code);
139 struct ev_loop *get_loop() const;
144 ev_timer settings_timerev_;
145 std::map<int32_t, std::unique_ptr<Stream>> id2stream_;
147 std::function<int(Http2Handler &)> read_, write_;
149 nghttp2_session *session_;
152 const uint8_t *data_pending_;
153 size_t data_pendinglen_;
159 HttpServer(const Config *config);
162 const Config *get_config() const;
165 const Config *config_;
168 ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id,
169 uint8_t *buf, size_t length, int *eof,
170 nghttp2_data_source *source, void *user_data);
172 } // namespace nghttp2
174 #endif // HTTP_SERVER_H