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
cc54195f
Commit
cc54195f
authored
Jul 31, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added mg_forward()
parent
e2fb707d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
28 deletions
+38
-28
mongoose.c
mongoose.c
+36
-28
mongoose.h
mongoose.h
+2
-0
No files found.
mongoose.c
View file @
cc54195f
...
...
@@ -1297,6 +1297,7 @@ enum endpoint_type {
#define MG_LONG_RUNNING NSF_USER_2
#define MG_CGI_CONN NSF_USER_3
#define MG_PROXY_CONN NSF_USER_4
#define MG_PROXY_DONT_PARSE NSF_USER_5
struct
connection
{
struct
ns_connection
*
ns_conn
;
// NOTE(lsm): main.c depends on this order
...
...
@@ -4086,12 +4087,38 @@ int mg_terminate_ssl(struct mg_connection *c, const char *cert) {
}
#endif
int
mg_forward
(
struct
mg_connection
*
c
,
const
char
*
host
,
int
port
,
int
ssl
)
{
struct
connection
*
conn
=
MG_CONN_2_CONN
(
c
);
struct
ns_server
*
server
=
&
conn
->
server
->
ns_server
;
struct
ns_connection
*
pc
;
if
((
pc
=
ns_connect
(
server
,
host
,
port
,
ssl
,
conn
))
==
NULL
)
return
0
;
// Interlink two connections
pc
->
flags
|=
MG_PROXY_CONN
;
conn
->
endpoint_type
=
EP_PROXY
;
conn
->
endpoint
.
nc
=
pc
;
DBG
((
"%p [%s] -> %p %p"
,
conn
,
c
->
uri
,
pc
,
conn
->
ns_conn
->
ssl
));
if
(
strcmp
(
c
->
request_method
,
"CONNECT"
)
==
0
)
{
// For CONNECT request, reply with 200 OK. Tunnel is established.
mg_printf
(
c
,
"%s"
,
"HTTP/1.1 200 OK
\r\n\r\n
"
);
conn
->
request_len
=
0
;
free
(
conn
->
request
);
conn
->
request
=
NULL
;
}
else
{
// Strip "http://host:port" part from the URI
if
(
memcmp
(
c
->
uri
,
"http://"
,
7
)
==
0
)
c
->
uri
+=
7
;
while
(
*
c
->
uri
!=
'\0'
&&
*
c
->
uri
!=
'/'
)
c
->
uri
++
;
proxy_request
(
pc
,
c
);
}
return
1
;
}
static
void
proxify_connection
(
struct
connection
*
conn
)
{
char
proto
[
10
],
host
[
500
],
cert
[
500
];
unsigned
short
port
=
80
;
struct
mg_connection
*
c
=
&
conn
->
mg_conn
;
struct
ns_server
*
server
=
&
conn
->
server
->
ns_server
;
struct
ns_connection
*
pc
=
NULL
;
int
n
=
0
;
const
char
*
url
=
c
->
uri
;
...
...
@@ -4119,26 +4146,7 @@ static void proxify_connection(struct connection *conn) {
}
#endif
if
(
n
>
0
&&
(
pc
=
ns_connect
(
server
,
host
,
port
,
conn
->
ns_conn
->
ssl
!=
NULL
,
conn
))
!=
NULL
)
{
// Interlink two connections
pc
->
flags
|=
MG_PROXY_CONN
;
conn
->
endpoint_type
=
EP_PROXY
;
conn
->
endpoint
.
nc
=
pc
;
DBG
((
"%p [%s] -> %p %p"
,
conn
,
c
->
uri
,
pc
,
conn
->
ns_conn
->
ssl
));
if
(
strcmp
(
c
->
request_method
,
"CONNECT"
)
==
0
)
{
// For CONNECT request, reply with 200 OK. Tunnel is established.
mg_printf
(
c
,
"%s"
,
"HTTP/1.1 200 OK
\r\n\r\n
"
);
conn
->
request_len
=
0
;
free
(
conn
->
request
);
conn
->
request
=
NULL
;
}
else
{
// For other methods, forward the request to the target host.
c
->
uri
+=
n
;
proxy_request
(
pc
,
c
);
}
if
(
n
>
0
&&
mg_forward
(
c
,
host
,
port
,
conn
->
ns_conn
->
ssl
!=
NULL
))
{
}
else
{
conn
->
ns_conn
->
flags
|=
NSF_CLOSE_IMMEDIATELY
;
}
...
...
@@ -4335,7 +4343,7 @@ static void try_parse(struct connection *conn) {
}
static
void
do_proxy
(
struct
connection
*
conn
)
{
if
(
conn
->
request_len
==
0
)
{
if
(
0
&&
conn
->
request_len
==
0
)
{
try_parse
(
conn
);
DBG
((
"%p parsing -> %d"
,
conn
,
conn
->
request_len
));
if
(
conn
->
request_len
>
0
&&
call_user
(
conn
,
MG_REQUEST
)
==
MG_FALSE
)
{
...
...
mongoose.h
View file @
cc54195f
...
...
@@ -130,6 +130,8 @@ int mg_authorize_digest(struct mg_connection *c, FILE *fp);
int
mg_url_encode
(
const
char
*
src
,
size_t
s_len
,
char
*
dst
,
size_t
dst_len
);
int
mg_url_decode
(
const
char
*
src
,
int
src_len
,
char
*
dst
,
int
dst_len
,
int
);
int
mg_terminate_ssl
(
struct
mg_connection
*
c
,
const
char
*
cert
);
int
mg_forward
(
struct
mg_connection
*
,
const
char
*
host
,
int
port
,
int
use_ssl
);
// Templates support
struct
mg_expansion
{
...
...
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