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-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();
|
|
|
|
void add_downstream(Downstream *downstream);
|
|
|
|
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
|
|
|
|
2013-07-26 12:33:25 +02:00
|
|
|
int rst_stream(Downstream *downstream, nghttp2_error_code error_code);
|
2013-10-29 16:51:01 +01:00
|
|
|
// To send WINDOW_UPDATE for a connection, specify nullptr to
|
|
|
|
// |downstream|.
|
2013-10-29 16:07:35 +01:00
|
|
|
int window_update(Downstream *downstream, int32_t window_size_increment);
|
2013-12-25 16:23:07 +01:00
|
|
|
int terminate_session(nghttp2_error_code 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);
|
2013-02-08 13:46:58 +01:00
|
|
|
virtual int resume_read(IOCtrlReason reason, Downstream *downstream);
|
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-02 16:07:46 +02:00
|
|
|
int handle_ign_data_chunk(size_t len);
|
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_;
|
2014-07-02 16:07:46 +02:00
|
|
|
// Received DATA frame size while it is not sent to backend before
|
|
|
|
// any connection-level WINDOW_UPDATE
|
|
|
|
int32_t recv_ign_window_size_;
|
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
|