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
e6f8d409
Commit
e6f8d409
authored
Jan 20, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SSL redirect, using Host: header
parent
7e051206
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
mongoose.c
mongoose.c
+17
-5
No files found.
mongoose.c
View file @
e6f8d409
...
@@ -4225,13 +4225,28 @@ static int get_first_ssl_listener_index(const struct mg_context *ctx) {
...
@@ -4225,13 +4225,28 @@ static int get_first_ssl_listener_index(const struct mg_context *ctx) {
return
index
;
return
index
;
}
}
static
void
redirect_to_https_port
(
struct
mg_connection
*
conn
,
int
ssl_index
)
{
char
host
[
1025
];
const
char
*
host_header
;
if
((
host_header
=
mg_get_header
(
conn
,
"Host"
))
==
NULL
||
sscanf
(
host_header
,
"%1024[^:]"
,
host
)
==
0
)
{
// Cannot get host from the Host: header. Fallback to our IP address.
sockaddr_to_string
(
host
,
sizeof
(
host
),
&
conn
->
client
.
lsa
);
}
mg_printf
(
conn
,
"HTTP/1.1 302 Found
\r\n
Location: https://%s:%d%s
\r\n\r\n
"
,
host
,
(
int
)
ntohs
(
conn
->
ctx
->
listening_sockets
[
ssl_index
].
lsa
.
sin
.
sin_port
),
conn
->
request_info
.
uri
);
}
// This is the heart of the Mongoose's logic.
// This is the heart of the Mongoose's logic.
// This function is called when the request is read, parsed and validated,
// This function is called when the request is read, parsed and validated,
// and Mongoose must decide what action to take: serve a file, or
// and Mongoose must decide what action to take: serve a file, or
// a directory, or call embedded function, etcetera.
// a directory, or call embedded function, etcetera.
static
void
handle_request
(
struct
mg_connection
*
conn
)
{
static
void
handle_request
(
struct
mg_connection
*
conn
)
{
struct
mg_request_info
*
ri
=
&
conn
->
request_info
;
struct
mg_request_info
*
ri
=
&
conn
->
request_info
;
char
path
[
PATH_MAX
]
,
local_ip
[
40
]
;
char
path
[
PATH_MAX
];
int
uri_len
,
ssl_index
;
int
uri_len
,
ssl_index
;
struct
file
file
=
STRUCT_FILE_INITIALIZER
;
struct
file
file
=
STRUCT_FILE_INITIALIZER
;
...
@@ -4248,10 +4263,7 @@ static void handle_request(struct mg_connection *conn) {
...
@@ -4248,10 +4263,7 @@ static void handle_request(struct mg_connection *conn) {
DEBUG_TRACE
((
"%s"
,
ri
->
uri
));
DEBUG_TRACE
((
"%s"
,
ri
->
uri
));
if
(
!
conn
->
client
.
is_ssl
&&
conn
->
client
.
ssl_redir
&&
if
(
!
conn
->
client
.
is_ssl
&&
conn
->
client
.
ssl_redir
&&
(
ssl_index
=
get_first_ssl_listener_index
(
conn
->
ctx
))
>
-
1
)
{
(
ssl_index
=
get_first_ssl_listener_index
(
conn
->
ctx
))
>
-
1
)
{
sockaddr_to_string
(
local_ip
,
sizeof
(
local_ip
),
&
conn
->
client
.
lsa
);
redirect_to_https_port
(
conn
,
ssl_index
);
mg_printf
(
conn
,
"HTTP/1.1 302 Found
\r\n
Location: https://%s:%d%s
\r\n\r\n
"
,
local_ip
,
(
int
)
ntohs
(
conn
->
ctx
->
listening_sockets
[
ssl_index
].
lsa
.
sin
.
sin_port
),
ri
->
uri
);
}
else
if
(
!
is_put_or_delete_request
(
conn
)
&&
}
else
if
(
!
is_put_or_delete_request
(
conn
)
&&
!
check_authorization
(
conn
,
path
))
{
!
check_authorization
(
conn
,
path
))
{
send_authorization_request
(
conn
);
send_authorization_request
(
conn
);
...
...
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