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"
30 #include <sys/types.h>
40 #include <openssl/ssl.h>
44 #include <nghttp2/nghttp2.h>
52 std::map<std::string, std::vector<std::string>> push;
56 std::string private_key_file;
57 std::string cert_file;
58 std::string dh_param_file;
60 ev_tstamp stream_read_timeout;
61 ev_tstamp stream_write_timeout;
65 size_t max_concurrent_streams;
66 ssize_t header_table_size;
83 FileEntry(std::string path, int64_t length, int64_t mtime, int fd)
84 : path(std::move(path)), length(length), mtime(mtime), dlprev(nullptr),
85 dlnext(nullptr), fd(fd), usecount(1) {}
89 FileEntry *dlprev, *dlnext;
96 Http2Handler *handler;
103 http2::HeaderIndex hdidx;
105 Stream(Http2Handler *handler, int32_t stream_id);
113 Http2Handler(Sessions *sessions, int fd, SSL *ssl, int64_t session_id);
120 int connection_made();
121 int verify_npn_result();
123 int submit_file_response(const std::string &status, Stream *stream,
124 time_t last_modified, off_t file_length,
125 nghttp2_data_provider *data_prd);
127 int submit_response(const std::string &status, int32_t stream_id,
128 nghttp2_data_provider *data_prd);
130 int submit_response(const std::string &status, int32_t stream_id,
131 const Headers &headers, nghttp2_data_provider *data_prd);
133 int submit_non_final_response(const std::string &status, int32_t stream_id);
135 int submit_push_promise(Stream *stream, const std::string &push_path);
137 int submit_rst_stream(Stream *stream, uint32_t error_code);
139 void add_stream(int32_t stream_id, std::unique_ptr<Stream> stream);
140 void remove_stream(int32_t stream_id);
141 Stream *get_stream(int32_t stream_id);
142 int64_t session_id() const;
143 Sessions *get_sessions() const;
144 const Config *get_config() const;
145 void remove_settings_timer();
146 void terminate_session(uint32_t error_code);
156 struct ev_loop *get_loop() const;
158 using WriteBuf = Buffer<65536>;
165 ev_timer settings_timerev_;
166 std::map<int32_t, std::unique_ptr<Stream>> id2stream_;
168 std::function<int(Http2Handler &)> read_, write_;
170 nghttp2_session *session_;
173 const uint8_t *data_pending_;
174 size_t data_pendinglen_;
185 HttpServer(const Config *config);
188 const Config *get_config() const;
189 const StatusPage *get_status_page(int status) const;
192 std::vector<StatusPage> status_pages_;
193 const Config *config_;
196 ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id,
197 uint8_t *buf, size_t length, int *eof,
198 nghttp2_data_source *source, void *user_data);
200 } // namespace nghttp2
202 #endif // HTTP_SERVER_H