Forward client request to the backend connection, rewriting the Host header
| 19 | |
| 20 | // Forward client request to the backend connection, rewriting the Host header |
| 21 | static void forward_request(struct mg_http_message *hm, |
| 22 | struct mg_connection *c) { |
| 23 | size_t i, max = sizeof(hm->headers) / sizeof(hm->headers[0]); |
| 24 | struct mg_str host = mg_url_host(s_backend_url); |
| 25 | mg_printf(c, "%.*s\r\n", |
| 26 | (int) (hm->proto.buf + hm->proto.len - hm->message.buf), |
| 27 | hm->message.buf); |
| 28 | for (i = 0; i < max && hm->headers[i].name.len > 0; i++) { |
| 29 | struct mg_str *k = &hm->headers[i].name, *v = &hm->headers[i].value; |
| 30 | if (mg_strcmp(*k, mg_str("Host")) == 0) v = &host; |
| 31 | mg_printf(c, "%.*s: %.*s\r\n", (int) k->len, k->buf, (int) v->len, v->buf); |
| 32 | } |
| 33 | mg_send(c, "\r\n", 2); |
| 34 | mg_send(c, hm->body.buf, hm->body.len); |
| 35 | MG_DEBUG(("FORWARDING: %.*s %.*s", (int) hm->method.len, hm->method.buf, |
| 36 | (int) hm->uri.len, hm->uri.buf)); |
| 37 | } |
| 38 | |
| 39 | static void fn2(struct mg_connection *c, int ev, void *ev_data) { |
| 40 | struct mg_connection *c2 = (struct mg_connection *) c->fn_data; |