mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-18 11:28:13 +08:00
Expose reverse proxy API for dynamic mounts
PUBLISHED_FROM=00772400bce7c15368d91741092ebc8ab0842e19
This commit is contained in:
parent
900bbe724a
commit
a4c668e37a
@ -8,6 +8,7 @@ items:
|
||||
- { name: mg_get_http_var.md }
|
||||
- { name: mg_http_check_digest_auth.md }
|
||||
- { name: mg_http_parse_header.md }
|
||||
- { name: mg_http_reverse_proxy.md }
|
||||
- { name: mg_http_send_error.md }
|
||||
- { name: mg_http_send_redirect.md }
|
||||
- { name: mg_http_serve_file.md }
|
||||
|
19
docs/c-api/http_server.h/mg_http_reverse_proxy.md
Normal file
19
docs/c-api/http_server.h/mg_http_reverse_proxy.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
title: "mg_http_reverse_proxy()"
|
||||
decl_name: "mg_http_reverse_proxy"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
void mg_http_reverse_proxy(struct mg_connection *nc,
|
||||
const struct http_message *hm, struct mg_str mount,
|
||||
struct mg_str upstream);
|
||||
---
|
||||
|
||||
Proxies a given request to a given upstream http server. The path prefix
|
||||
in `mount` will be stripped of the path requested to the upstream server,
|
||||
e.g. if mount is /api and upstream is http://localhost:8001/foo
|
||||
then an incoming request to /api/bar will cause a request to
|
||||
http://localhost:8001/foo/bar
|
||||
|
||||
EXPERIMENTAL API. Please use http_serve_http + url_rewrites if a static
|
||||
mapping is good enough.
|
||||
|
13
mongoose.c
13
mongoose.c
@ -5845,8 +5845,9 @@ static void mg_reverse_proxy_handler(struct mg_connection *nc, int ev,
|
||||
}
|
||||
}
|
||||
|
||||
void mg_handle_reverse_proxy(struct mg_connection *nc, struct http_message *hm,
|
||||
struct mg_str mount, struct mg_str upstream) {
|
||||
void mg_http_reverse_proxy(struct mg_connection *nc,
|
||||
const struct http_message *hm, struct mg_str mount,
|
||||
struct mg_str upstream) {
|
||||
struct mg_connection *be;
|
||||
char burl[256], *purl = burl;
|
||||
char *addr = NULL;
|
||||
@ -5889,6 +5890,12 @@ void mg_handle_reverse_proxy(struct mg_connection *nc, struct http_message *hm,
|
||||
mg_printf(be, "Content-Length: %" SIZE_T_FMT "\r\n", hm->body.len);
|
||||
continue;
|
||||
}
|
||||
/* We don't support proxying Expect: 100-continue. */
|
||||
if (mg_vcasecmp(&hn, "Expect") == 0 &&
|
||||
mg_vcasecmp(&hv, "100-continue") == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mg_printf(be, "%.*s: %.*s\r\n", (int) hn.len, hn.p, (int) hv.len, hv.p);
|
||||
}
|
||||
|
||||
@ -5909,7 +5916,7 @@ static int mg_http_handle_forwarding(struct mg_connection *nc,
|
||||
while ((rewrites = mg_next_comma_list_entry(rewrites, &a, &b)) != NULL) {
|
||||
if (mg_strncmp(a, hm->uri, a.len) == 0) {
|
||||
if (mg_strncmp(b, p1, p1.len) == 0 || mg_strncmp(b, p2, p2.len) == 0) {
|
||||
mg_handle_reverse_proxy(nc, hm, a, b);
|
||||
mg_http_reverse_proxy(nc, hm, a, b);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
16
mongoose.h
16
mongoose.h
@ -3502,6 +3502,22 @@ void mg_send_head(struct mg_connection *n, int status_code,
|
||||
*/
|
||||
void mg_printf_html_escape(struct mg_connection *nc, const char *fmt, ...);
|
||||
|
||||
#if MG_ENABLE_HTTP_URL_REWRITES
|
||||
/*
|
||||
* Proxies a given request to a given upstream http server. The path prefix
|
||||
* in `mount` will be stripped of the path requested to the upstream server,
|
||||
* e.g. if mount is /api and upstream is http://localhost:8001/foo
|
||||
* then an incoming request to /api/bar will cause a request to
|
||||
* http://localhost:8001/foo/bar
|
||||
*
|
||||
* EXPERIMENTAL API. Please use http_serve_http + url_rewrites if a static
|
||||
* mapping is good enough.
|
||||
*/
|
||||
void mg_http_reverse_proxy(struct mg_connection *nc,
|
||||
const struct http_message *hm, struct mg_str mount,
|
||||
struct mg_str upstream);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
Loading…
Reference in New Issue
Block a user