]> granicus.if.org Git - apache/blob - modules/http2/h2_proxy_session.h
On the 2.4.x branch:
[apache] / modules / http2 / h2_proxy_session.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef h2_proxy_session_h
18 #define h2_proxy_session_h
19
20 #define H2_ALEN(a)          (sizeof(a)/sizeof((a)[0]))
21
22 #include <nghttp2/nghttp2.h>
23
24 struct h2_proxy_iqueue;
25 struct h2_proxy_ihash_t;
26
27 typedef enum {
28     H2_STREAM_ST_IDLE,
29     H2_STREAM_ST_OPEN,
30     H2_STREAM_ST_RESV_LOCAL,
31     H2_STREAM_ST_RESV_REMOTE,
32     H2_STREAM_ST_CLOSED_INPUT,
33     H2_STREAM_ST_CLOSED_OUTPUT,
34     H2_STREAM_ST_CLOSED,
35 } h2_proxy_stream_state_t;
36
37 typedef enum {
38     H2_PROXYS_ST_INIT,             /* send initial SETTINGS, etc. */
39     H2_PROXYS_ST_DONE,             /* finished, connection close */
40     H2_PROXYS_ST_IDLE,             /* no streams to process */
41     H2_PROXYS_ST_BUSY,             /* read/write without stop */
42     H2_PROXYS_ST_WAIT,             /* waiting for tasks reporting back */
43     H2_PROXYS_ST_LOCAL_SHUTDOWN,   /* we announced GOAWAY */
44     H2_PROXYS_ST_REMOTE_SHUTDOWN,  /* client announced GOAWAY */
45 } h2_proxys_state;
46
47 typedef enum {
48     H2_PROXYS_EV_INIT,             /* session was initialized */
49     H2_PROXYS_EV_LOCAL_GOAWAY,     /* we send a GOAWAY */
50     H2_PROXYS_EV_REMOTE_GOAWAY,    /* remote send us a GOAWAY */
51     H2_PROXYS_EV_CONN_ERROR,       /* connection error */
52     H2_PROXYS_EV_PROTO_ERROR,      /* protocol error */
53     H2_PROXYS_EV_CONN_TIMEOUT,     /* connection timeout */
54     H2_PROXYS_EV_NO_IO,            /* nothing has been read or written */
55     H2_PROXYS_EV_STREAM_SUBMITTED, /* stream has been submitted */
56     H2_PROXYS_EV_STREAM_DONE,      /* stream has been finished */
57     H2_PROXYS_EV_STREAM_RESUMED,   /* stream signalled availability of headers/data */
58     H2_PROXYS_EV_DATA_READ,        /* connection data has been read */
59     H2_PROXYS_EV_NGH2_DONE,        /* nghttp2 wants neither read nor write anything */
60     H2_PROXYS_EV_PRE_CLOSE,        /* connection will close after this */
61 } h2_proxys_event_t;
62
63
64 typedef struct h2_proxy_session h2_proxy_session;
65 typedef void h2_proxy_request_done(h2_proxy_session *s, request_rec *r,
66                                    apr_status_t status, int touched);
67
68 struct h2_proxy_session {
69     const char *id;
70     conn_rec *c;
71     proxy_conn_rec *p_conn;
72     proxy_server_conf *conf;
73     apr_pool_t *pool;
74     nghttp2_session *ngh2;   /* the nghttp2 session itself */
75     
76     unsigned int aborted : 1;
77     unsigned int check_ping : 1;
78     unsigned int h2_front : 1; /* if front-end connection is HTTP/2 */
79
80     h2_proxy_request_done *done;
81     void *user_data;
82     
83     unsigned char window_bits_stream;
84     unsigned char window_bits_connection;
85
86     h2_proxys_state state;
87     apr_interval_time_t wait_timeout;
88
89     struct h2_proxy_ihash_t *streams;
90     struct h2_proxy_iqueue *suspended;
91     apr_size_t remote_max_concurrent;
92     int last_stream_id;     /* last stream id processed by backend, or 0 */
93     apr_time_t last_frame_received;
94     
95     apr_bucket_brigade *input;
96     apr_bucket_brigade *output;
97 };
98
99 h2_proxy_session *h2_proxy_session_setup(const char *id, proxy_conn_rec *p_conn,
100                                          proxy_server_conf *conf,
101                                          int h2_front, 
102                                          unsigned char window_bits_connection,
103                                          unsigned char window_bits_stream,
104                                          h2_proxy_request_done *done);
105
106 apr_status_t h2_proxy_session_submit(h2_proxy_session *s, const char *url,
107                                      request_rec *r, int standalone);
108                        
109 /** 
110  * Perform a step in processing the proxy session. Will return aftert
111  * one read/write cycle and indicate session status by status code.
112  * @param s the session to process
113  * @return APR_EAGAIN  when processing needs to be invoked again
114  *         APR_SUCCESS when all streams have been processed, session still live
115  *         APR_EOF     when the session has been terminated
116  */
117 apr_status_t h2_proxy_session_process(h2_proxy_session *s);
118
119 void h2_proxy_session_cancel_all(h2_proxy_session *s);
120
121 void h2_proxy_session_cleanup(h2_proxy_session *s, h2_proxy_request_done *done);
122
123 void h2_proxy_session_update_window(h2_proxy_session *s, 
124                                     conn_rec *c, apr_off_t bytes);
125
126 #define H2_PROXY_REQ_URL_NOTE   "h2-proxy-req-url"
127
128 #endif /* h2_proxy_session_h */