|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef h2_proxy_session_h
|
|
Packit |
90a5c9 |
#define h2_proxy_session_h
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define H2_ALEN(a) (sizeof(a)/sizeof((a)[0]))
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <nghttp2/nghttp2.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_proxy_iqueue;
|
|
Packit |
90a5c9 |
struct h2_proxy_ihash_t;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef enum {
|
|
Packit |
90a5c9 |
H2_STREAM_ST_IDLE,
|
|
Packit |
90a5c9 |
H2_STREAM_ST_OPEN,
|
|
Packit |
90a5c9 |
H2_STREAM_ST_RESV_LOCAL,
|
|
Packit |
90a5c9 |
H2_STREAM_ST_RESV_REMOTE,
|
|
Packit |
90a5c9 |
H2_STREAM_ST_CLOSED_INPUT,
|
|
Packit |
90a5c9 |
H2_STREAM_ST_CLOSED_OUTPUT,
|
|
Packit |
90a5c9 |
H2_STREAM_ST_CLOSED,
|
|
Packit |
90a5c9 |
} h2_proxy_stream_state_t;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef enum {
|
|
Packit |
90a5c9 |
H2_PROXYS_ST_INIT, /* send initial SETTINGS, etc. */
|
|
Packit |
90a5c9 |
H2_PROXYS_ST_DONE, /* finished, connection close */
|
|
Packit |
90a5c9 |
H2_PROXYS_ST_IDLE, /* no streams to process */
|
|
Packit |
90a5c9 |
H2_PROXYS_ST_BUSY, /* read/write without stop */
|
|
Packit |
90a5c9 |
H2_PROXYS_ST_WAIT, /* waiting for tasks reporting back */
|
|
Packit |
90a5c9 |
H2_PROXYS_ST_LOCAL_SHUTDOWN, /* we announced GOAWAY */
|
|
Packit |
90a5c9 |
H2_PROXYS_ST_REMOTE_SHUTDOWN, /* client announced GOAWAY */
|
|
Packit |
90a5c9 |
} h2_proxys_state;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef enum {
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_INIT, /* session was initialized */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_LOCAL_GOAWAY, /* we send a GOAWAY */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_REMOTE_GOAWAY, /* remote send us a GOAWAY */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_CONN_ERROR, /* connection error */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_PROTO_ERROR, /* protocol error */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_CONN_TIMEOUT, /* connection timeout */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_NO_IO, /* nothing has been read or written */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_STREAM_SUBMITTED, /* stream has been submitted */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_STREAM_DONE, /* stream has been finished */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_STREAM_RESUMED, /* stream signalled availability of headers/data */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_DATA_READ, /* connection data has been read */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_NGH2_DONE, /* nghttp2 wants neither read nor write anything */
|
|
Packit |
90a5c9 |
H2_PROXYS_EV_PRE_CLOSE, /* connection will close after this */
|
|
Packit |
90a5c9 |
} h2_proxys_event_t;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct h2_proxy_session h2_proxy_session;
|
|
Packit |
90a5c9 |
typedef void h2_proxy_request_done(h2_proxy_session *s, request_rec *r,
|
|
Packit |
90a5c9 |
apr_status_t status, int touched);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_proxy_session {
|
|
Packit |
90a5c9 |
const char *id;
|
|
Packit |
90a5c9 |
conn_rec *c;
|
|
Packit |
90a5c9 |
proxy_conn_rec *p_conn;
|
|
Packit |
90a5c9 |
proxy_server_conf *conf;
|
|
Packit |
90a5c9 |
apr_pool_t *pool;
|
|
Packit |
90a5c9 |
nghttp2_session *ngh2; /* the nghttp2 session itself */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
unsigned int aborted : 1;
|
|
Packit |
90a5c9 |
unsigned int check_ping : 1;
|
|
Packit |
90a5c9 |
unsigned int h2_front : 1; /* if front-end connection is HTTP/2 */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_proxy_request_done *done;
|
|
Packit |
90a5c9 |
void *user_data;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
unsigned char window_bits_stream;
|
|
Packit |
90a5c9 |
unsigned char window_bits_connection;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_proxys_state state;
|
|
Packit |
90a5c9 |
apr_interval_time_t wait_timeout;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct h2_proxy_ihash_t *streams;
|
|
Packit |
90a5c9 |
struct h2_proxy_iqueue *suspended;
|
|
Packit |
90a5c9 |
apr_size_t remote_max_concurrent;
|
|
Packit |
90a5c9 |
int last_stream_id; /* last stream id processed by backend, or 0 */
|
|
Packit |
90a5c9 |
apr_time_t last_frame_received;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_bucket_brigade *input;
|
|
Packit |
90a5c9 |
apr_bucket_brigade *output;
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
h2_proxy_session *h2_proxy_session_setup(const char *id, proxy_conn_rec *p_conn,
|
|
Packit |
90a5c9 |
proxy_server_conf *conf,
|
|
Packit |
90a5c9 |
int h2_front,
|
|
Packit |
90a5c9 |
unsigned char window_bits_connection,
|
|
Packit |
90a5c9 |
unsigned char window_bits_stream,
|
|
Packit |
90a5c9 |
h2_proxy_request_done *done);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t h2_proxy_session_submit(h2_proxy_session *s, const char *url,
|
|
Packit |
90a5c9 |
request_rec *r, int standalone);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Perform a step in processing the proxy session. Will return aftert
|
|
Packit |
90a5c9 |
* one read/write cycle and indicate session status by status code.
|
|
Packit |
90a5c9 |
* @param s the session to process
|
|
Packit |
90a5c9 |
* @return APR_EAGAIN when processing needs to be invoked again
|
|
Packit |
90a5c9 |
* APR_SUCCESS when all streams have been processed, session still live
|
|
Packit |
90a5c9 |
* APR_EOF when the session has been terminated
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t h2_proxy_session_process(h2_proxy_session *s);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void h2_proxy_session_cancel_all(h2_proxy_session *s);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void h2_proxy_session_cleanup(h2_proxy_session *s, h2_proxy_request_done *done);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void h2_proxy_session_update_window(h2_proxy_session *s,
|
|
Packit |
90a5c9 |
conn_rec *c, apr_off_t bytes);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define H2_PROXY_REQ_URL_NOTE "h2-proxy-req-url"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#endif /* h2_proxy_session_h */
|