Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
a4c668e3
Commit
a4c668e3
authored
Oct 27, 2016
by
Marko Mikulicic
Committed by
Cesanta Bot
Oct 27, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose reverse proxy API for dynamic mounts
PUBLISHED_FROM=00772400bce7c15368d91741092ebc8ab0842e19
parent
900bbe72
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
3 deletions
+46
-3
intro.md
docs/c-api/http_server.h/intro.md
+1
-0
mg_http_reverse_proxy.md
docs/c-api/http_server.h/mg_http_reverse_proxy.md
+19
-0
mongoose.c
mongoose.c
+10
-3
mongoose.h
mongoose.h
+16
-0
No files found.
docs/c-api/http_server.h/intro.md
View file @
a4c668e3
...
...
@@ -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
}
...
...
docs/c-api/http_server.h/mg_http_reverse_proxy.md
0 → 100644
View file @
a4c668e3
---
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.
mongoose.c
View file @
a4c668e3
...
...
@@ -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_h
andle
_reverse_proxy
(
nc
,
hm
,
a
,
b
);
mg_h
ttp
_reverse_proxy
(
nc
,
hm
,
a
,
b
);
return
1
;
}
}
...
...
mongoose.h
View file @
a4c668e3
...
...
@@ -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 */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment