MCPcopy Create free account
hub / github.com/apache/httpd / proxy_wstunnel_request

Function proxy_wstunnel_request

modules/proxy/mod_proxy_wstunnel.c:163–342  ·  view source on GitHub ↗

* process the request and write the response. */

Source from the content-addressed store, hash-verified

161 * process the request and write the response.
162 */
163static int proxy_wstunnel_request(apr_pool_t *p, request_rec *r,
164 proxy_conn_rec *conn,
165 proxy_worker *worker,
166 proxy_server_conf *conf,
167 apr_uri_t *uri,
168 char *url, char *server_portstr)
169{
170 apr_status_t rv;
171 apr_pollset_t *pollset;
172 apr_pollfd_t pollfd;
173 const apr_pollfd_t *signalled;
174 apr_int32_t pollcnt, pi;
175 apr_int16_t pollevent;
176 conn_rec *c = r->connection;
177 apr_socket_t *sock = conn->sock;
178 conn_rec *backconn = conn->connection;
179 char *buf;
180 apr_bucket_brigade *header_brigade;
181 apr_bucket *e;
182 char *old_cl_val = NULL;
183 char *old_te_val = NULL;
184 apr_bucket_brigade *bb = apr_brigade_create(p, c->bucket_alloc);
185 apr_socket_t *client_socket = ap_get_conn_socket(c);
186 int done = 0, replied = 0;
187 const char *upgrade_method = *worker->s->upgrade ? worker->s->upgrade : "WebSocket";
188
189 header_brigade = apr_brigade_create(p, backconn->bucket_alloc);
190
191 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, "sending request");
192
193 rv = ap_proxy_create_hdrbrgd(p, header_brigade, r, conn,
194 worker, conf, uri, url, server_portstr,
195 &old_cl_val, &old_te_val);
196 if (rv != OK) {
197 return rv;
198 }
199
200 if (ap_cstr_casecmp(upgrade_method, "NONE") == 0) {
201 buf = apr_pstrdup(p, "Upgrade: WebSocket" CRLF "Connection: Upgrade" CRLF CRLF);
202 } else if (ap_cstr_casecmp(upgrade_method, "ANY") == 0) {
203 const char *upgrade;
204 upgrade = apr_table_get(r->headers_in, "Upgrade");
205 buf = apr_pstrcat(p, "Upgrade: ", upgrade, CRLF "Connection: Upgrade" CRLF CRLF, NULL);
206 } else {
207 buf = apr_pstrcat(p, "Upgrade: ", upgrade_method, CRLF "Connection: Upgrade" CRLF CRLF, NULL);
208 }
209 ap_xlate_proto_to_ascii(buf, strlen(buf));
210 e = apr_bucket_pool_create(buf, strlen(buf), p, c->bucket_alloc);
211 APR_BRIGADE_INSERT_TAIL(header_brigade, e);
212
213 if ((rv = ap_proxy_pass_brigade(backconn->bucket_alloc, r, conn, backconn,
214 header_brigade, 1)) != OK)
215 return rv;
216
217 apr_brigade_cleanup(header_brigade);
218
219 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, "setting up poll()");
220

Callers 1

proxy_wstunnel_handlerFunction · 0.85

Calls 7

ap_get_conn_socketFunction · 0.85
ap_proxy_create_hdrbrgdFunction · 0.85
ap_cstr_casecmpFunction · 0.85
ap_xlate_proto_to_asciiFunction · 0.85
ap_proxy_pass_brigadeFunction · 0.85

Tested by

no test coverage detected