2012-06-04 16:48:31 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-06-04 16:48:31 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 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.
|
|
|
|
*/
|
2013-07-26 13:12:55 +02:00
|
|
|
#ifndef SHRPX_HTTP2_UPSTREAM_H
|
|
|
|
#define SHRPX_HTTP2_UPSTREAM_H
|
2012-06-04 16:48:31 +02:00
|
|
|
|
|
|
|
#include "shrpx.h"
|
|
|
|
|
2013-09-26 14:46:35 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
#include <ev.h>
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#include <nghttp2/nghttp2.h>
|
2012-06-04 16:48:31 +02:00
|
|
|
|
|
|
|
#include "shrpx_upstream.h"
|
|
|
|
#include "shrpx_downstream_queue.h"
|
2014-12-27 18:59:06 +01:00
|
|
|
#include "memchunk.h"
|
|
|
|
|
|
|
|
using namespace nghttp2;
|
2012-06-04 16:48:31 +02:00
|
|
|
|
|
|
|
namespace shrpx {
|
|
|
|
|
|
|
|
class ClientHandler;
|
2013-08-03 11:51:01 +02:00
|
|
|
class HttpsUpstream;
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2013-07-26 12:38:54 +02:00
|
|
|
class Http2Upstream : public Upstream {
|
2012-06-04 16:48:31 +02:00
|
|
|
public:
|
2013-07-26 12:38:54 +02:00
|
|
|
Http2Upstream(ClientHandler *handler);
|
|
|
|
virtual ~Http2Upstream();
|
2012-06-04 16:48:31 +02:00
|
|
|
virtual int on_read();
|
2012-06-04 20:11:43 +02:00
|
|
|
virtual int on_write();
|
2014-08-09 11:47:45 +02:00
|
|
|
virtual int on_timeout(Downstream *downstream);
|
2014-06-27 15:34:54 +02:00
|
|
|
virtual int on_downstream_abort_request(Downstream *downstream,
|
|
|
|
unsigned int status_code);
|
2014-11-27 15:39:04 +01:00
|
|
|
virtual ClientHandler *get_client_handler() const;
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
virtual int downstream_read(DownstreamConnection *dconn);
|
|
|
|
virtual int downstream_write(DownstreamConnection *dconn);
|
|
|
|
virtual int downstream_eof(DownstreamConnection *dconn);
|
|
|
|
virtual int downstream_error(DownstreamConnection *dconn, int events);
|
|
|
|
|
2014-08-18 15:59:31 +02:00
|
|
|
void add_pending_downstream(std::unique_ptr<Downstream> downstream);
|
2012-06-04 16:48:31 +02:00
|
|
|
void remove_downstream(Downstream *downstream);
|
2012-06-07 17:36:19 +02:00
|
|
|
|
2014-08-23 10:34:56 +02:00
|
|
|
int rst_stream(Downstream *downstream, uint32_t error_code);
|
|
|
|
int terminate_session(uint32_t error_code);
|
2013-09-08 07:29:18 +02:00
|
|
|
int error_reply(Downstream *downstream, unsigned int status_code);
|
2012-06-04 16:48:31 +02:00
|
|
|
|
2012-11-18 13:23:13 +01:00
|
|
|
virtual void pause_read(IOCtrlReason reason);
|
2014-08-21 14:22:16 +02:00
|
|
|
virtual int resume_read(IOCtrlReason reason, Downstream *downstream,
|
|
|
|
size_t consumed);
|
2012-11-18 13:23:13 +01:00
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
virtual int on_downstream_header_complete(Downstream *downstream);
|
2014-11-27 15:39:04 +01:00
|
|
|
virtual int on_downstream_body(Downstream *downstream, const uint8_t *data,
|
|
|
|
size_t len, bool flush);
|
2012-06-04 16:48:31 +02:00
|
|
|
virtual int on_downstream_body_complete(Downstream *downstream);
|
2012-06-09 18:36:30 +02:00
|
|
|
|
2014-11-18 17:59:09 +01:00
|
|
|
virtual void on_handler_delete();
|
2015-01-21 15:30:48 +01:00
|
|
|
virtual int on_downstream_reset(bool no_retry);
|
2015-09-03 15:29:16 +02:00
|
|
|
virtual int send_reply(Downstream *downstream, const uint8_t *body,
|
|
|
|
size_t bodylen);
|
2015-09-05 15:47:07 +02:00
|
|
|
virtual int initiate_push(Downstream *downstream, const char *uri,
|
|
|
|
size_t len);
|
2014-11-18 17:59:09 +01:00
|
|
|
|
2012-06-09 18:36:30 +02:00
|
|
|
bool get_flow_control() const;
|
2014-03-30 12:09:21 +02:00
|
|
|
// Perform HTTP/2 upgrade from |upstream|. On success, this object
|
2013-08-03 11:51:01 +02:00
|
|
|
// takes ownership of the |upstream|. This function returns 0 if it
|
|
|
|
// succeeds, or -1.
|
|
|
|
int upgrade_upstream(HttpsUpstream *upstream);
|
2014-12-27 18:59:06 +01:00
|
|
|
void start_settings_timer();
|
2013-10-30 16:44:23 +01:00
|
|
|
void stop_settings_timer();
|
2014-07-25 14:26:03 +02:00
|
|
|
int consume(int32_t stream_id, size_t len);
|
2014-07-25 17:40:06 +02:00
|
|
|
void log_response_headers(Downstream *downstream,
|
2014-11-27 15:39:04 +01:00
|
|
|
const std::vector<nghttp2_nv> &nva) const;
|
2014-12-04 17:07:00 +01:00
|
|
|
void start_downstream(Downstream *downstream);
|
2015-03-11 16:17:05 +01:00
|
|
|
void initiate_downstream(Downstream *downstream);
|
2014-11-05 16:56:07 +01:00
|
|
|
|
2015-01-21 17:43:56 +01:00
|
|
|
void submit_goaway();
|
|
|
|
void check_shutdown();
|
|
|
|
|
2015-02-07 08:09:49 +01:00
|
|
|
int prepare_push_promise(Downstream *downstream);
|
2015-09-05 11:59:19 +02:00
|
|
|
int submit_push_promise(const std::string &scheme,
|
|
|
|
const std::string &authority, const std::string &path,
|
|
|
|
Downstream *downstream);
|
2015-02-07 08:09:49 +01:00
|
|
|
|
2015-03-11 16:17:05 +01:00
|
|
|
int on_request_headers(Downstream *downstream, const nghttp2_frame *frame);
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
private:
|
2013-09-26 14:46:35 +02:00
|
|
|
std::unique_ptr<HttpsUpstream> pre_upstream_;
|
2014-12-27 18:59:06 +01:00
|
|
|
DownstreamQueue downstream_queue_;
|
|
|
|
ev_timer settings_timer_;
|
2015-01-21 17:43:56 +01:00
|
|
|
ev_timer shutdown_timer_;
|
|
|
|
ev_prepare prep_;
|
2013-12-06 15:17:38 +01:00
|
|
|
ClientHandler *handler_;
|
|
|
|
nghttp2_session *session_;
|
2014-12-27 18:59:06 +01:00
|
|
|
const uint8_t *data_pending_;
|
|
|
|
size_t data_pendinglen_;
|
2013-12-06 15:17:38 +01:00
|
|
|
bool flow_control_;
|
2015-01-21 17:43:56 +01:00
|
|
|
bool shutdown_handled_;
|
2012-06-04 16:48:31 +02:00
|
|
|
};
|
|
|
|
|
2015-02-24 07:21:10 +01:00
|
|
|
nghttp2_session_callbacks *create_http2_upstream_callbacks();
|
|
|
|
|
2012-06-04 16:48:31 +02:00
|
|
|
} // namespace shrpx
|
|
|
|
|
2013-07-26 13:12:55 +02:00
|
|
|
#endif // SHRPX_HTTP2_UPSTREAM_H
|