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>
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
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();
|
2012-06-04 16:48:31 +02:00
|
|
|
virtual int on_event();
|
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);
|
2012-06-04 16:48:31 +02:00
|
|
|
int send();
|
|
|
|
virtual ClientHandler* get_client_handler() const;
|
|
|
|
virtual bufferevent_data_cb get_downstream_readcb();
|
|
|
|
virtual bufferevent_data_cb get_downstream_writecb();
|
|
|
|
virtual bufferevent_event_cb get_downstream_eventcb();
|
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
|
|
|
Downstream* find_downstream(int32_t stream_id);
|
|
|
|
|
2013-11-04 09:53:57 +01:00
|
|
|
nghttp2_session* get_http2_session();
|
2012-06-04 16:48:31 +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);
|
|
|
|
virtual int on_downstream_body(Downstream *downstream,
|
2014-04-03 11:54:15 +02:00
|
|
|
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
|
|
|
|
|
|
|
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);
|
2013-10-30 16:44:23 +01:00
|
|
|
int start_settings_timer();
|
|
|
|
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,
|
|
|
|
const std::vector<nghttp2_nv>& nva) const;
|
2014-08-16 14:29:20 +02:00
|
|
|
void maintain_downstream_concurrency();
|
2014-08-18 15:59:31 +02:00
|
|
|
void initiate_downstream(std::unique_ptr<Downstream> downstream);
|
2012-06-04 16:48:31 +02:00
|
|
|
private:
|
|
|
|
DownstreamQueue downstream_queue_;
|
2013-09-26 14:46:35 +02:00
|
|
|
std::unique_ptr<HttpsUpstream> pre_upstream_;
|
2013-12-06 15:17:38 +01:00
|
|
|
ClientHandler *handler_;
|
|
|
|
nghttp2_session *session_;
|
2013-10-30 16:44:23 +01:00
|
|
|
event *settings_timerev_;
|
2013-12-06 15:17:38 +01:00
|
|
|
bool flow_control_;
|
2012-06-04 16:48:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace shrpx
|
|
|
|
|
2013-07-26 13:12:55 +02:00
|
|
|
#endif // SHRPX_HTTP2_UPSTREAM_H
|