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
e31f3058
Commit
e31f3058
authored
Jan 27, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test for rewrites
parent
83a9a726
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
14 deletions
+36
-14
mongoose.c
mongoose.c
+5
-4
unit_test.c
unit_test.c
+31
-10
No files found.
mongoose.c
View file @
e31f3058
...
...
@@ -1542,10 +1542,10 @@ static int must_hide_file(struct connection *conn, const char *path) {
static
int
convert_uri_to_file_name
(
struct
connection
*
conn
,
char
*
buf
,
size_t
buf_len
,
file_stat_t
*
st
)
{
struct
vec
a
,
b
;
const
char
*
rewrites
=
conn
->
server
->
config_options
[
URL_REWRITES
]
,
*
root
=
conn
->
server
->
config_options
[
DOCUMENT_ROOT
],
*
cgi_pat
=
conn
->
server
->
config_options
[
CGI_PATTERN
],
*
uri
=
conn
->
mg_conn
.
uri
;
const
char
*
rewrites
=
conn
->
server
->
config_options
[
URL_REWRITES
]
;
const
char
*
root
=
conn
->
server
->
config_options
[
DOCUMENT_ROOT
];
const
char
*
cgi_pat
=
conn
->
server
->
config_options
[
CGI_PATTERN
];
const
char
*
uri
=
conn
->
mg_conn
.
uri
;
char
*
p
;
int
match_len
;
...
...
@@ -3639,6 +3639,7 @@ int mg_connect(struct mg_server *server, const char *host, int port,
return
0
;
}
conn
->
server
=
server
;
conn
->
client_sock
=
sock
;
conn
->
endpoint_type
=
EP_CLIENT
;
conn
->
handler
=
handler
;
...
...
unit_test.c
View file @
e31f3058
...
...
@@ -538,31 +538,32 @@ static const char *test_parse_multipart(void) {
return
NULL
;
}
#ifdef MONGOOSE_USE_SSL
static
int
us1
(
struct
mg_connection
*
conn
)
{
static
const
char
*
file_name
=
"mongoose.h"
;
char
*
cp
=
(
char
*
)
conn
->
connection_param
;
int
file_size
;
if
(
conn
->
status_code
==
MG_CONNECT_SUCCESS
)
{
mg_printf
(
conn
,
"GET /%s HTTP/1.0
\r\n\r\n
"
,
file_name
);
mg_printf
(
conn
,
"GET /%s HTTP/1.0
\r\n\r\n
"
,
cp
);
return
0
;
}
else
if
(
conn
->
status_code
==
MG_DOWNLOAD_SUCCESS
)
{
char
*
file_data
=
read_file
(
file_name
,
&
file_size
);
sprintf
(
(
char
*
)
conn
->
connection_param
,
"%d"
,
(
size_t
)
file_size
==
conn
->
content_len
&&
memcmp
(
file_data
,
conn
->
content
,
file_size
)
==
0
?
1
:
0
);
sprintf
(
cp
,
"%d %s"
,
(
size_t
)
file_size
==
conn
->
content_len
&&
memcmp
(
file_data
,
conn
->
content
,
file_size
)
==
0
?
1
:
0
,
conn
->
query_string
==
NULL
?
"?"
:
conn
->
query_string
);
free
(
file_data
);
}
else
if
(
conn
->
status_code
==
MG_CONNECT_FAILURE
)
{
sprintf
(
(
char
*
)
conn
->
connection_param
,
"%s"
,
"cf"
);
sprintf
(
cp
,
"%s"
,
"cf"
);
}
else
{
sprintf
(
(
char
*
)
conn
->
connection_param
,
"%s"
,
"df"
);
sprintf
(
cp
,
"%s"
,
"df"
);
}
return
1
;
}
#ifdef MONGOOSE_USE_SSL
static
const
char
*
test_ssl
(
void
)
{
static
const
char
*
ssl_cert
=
"examples/ssl_cert.pem"
;
char
buf1
[
100
]
=
""
;
char
buf1
[
100
]
=
"
mongoose.h
"
;
struct
mg_server
*
server
=
mg_create_server
(
NULL
);
ASSERT
(
mg_set_option
(
server
,
"listening_port"
,
LISTENING_ADDR
)
==
NULL
);
...
...
@@ -571,8 +572,8 @@ static const char *test_ssl(void) {
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
atoi
(
HTTP_PORT
),
1
,
us1
,
buf1
)
==
1
);
{
int
i
;
for
(
i
=
0
;
i
<
50
;
i
++
)
mg_poll_server
(
server
,
1
000
);
}
ASSERT
(
strcmp
(
buf1
,
"1"
)
==
0
);
{
int
i
;
for
(
i
=
0
;
i
<
50
;
i
++
)
mg_poll_server
(
server
,
1
);
}
ASSERT
(
strcmp
(
buf1
,
"1
?
"
)
==
0
);
mg_destroy_server
(
&
server
);
return
NULL
;
}
...
...
@@ -586,6 +587,25 @@ static const char *test_mg_set_option(void) {
return
NULL
;
}
static
const
char
*
test_rewrites
(
void
)
{
char
buf1
[
100
]
=
"xx"
;
struct
mg_server
*
server
=
mg_create_server
(
NULL
);
ASSERT
(
mg_set_option
(
server
,
"listening_port"
,
"0"
)
==
NULL
);
ASSERT
(
mg_set_option
(
server
,
"document_root"
,
"."
)
==
NULL
);
ASSERT
(
mg_set_option
(
server
,
"url_rewrites"
,
"/xx=./mongoose.h"
)
==
NULL
);
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
atoi
(
mg_get_option
(
server
,
"listening_port"
)),
0
,
us1
,
buf1
)
==
1
);
{
int
i
;
for
(
i
=
0
;
i
<
50
;
i
++
)
mg_poll_server
(
server
,
1
);
}
//printf("[%s]\n", buf1);
ASSERT
(
strcmp
(
buf1
,
"1 ?"
)
==
0
);
mg_destroy_server
(
&
server
);
return
NULL
;
}
static
const
char
*
run_all_tests
(
void
)
{
RUN_TEST
(
test_should_keep_alive
);
RUN_TEST
(
test_match_prefix
);
...
...
@@ -602,6 +622,7 @@ static const char *run_all_tests(void) {
RUN_TEST
(
test_server
);
RUN_TEST
(
test_mg_connect
);
RUN_TEST
(
test_mg_set_option
);
RUN_TEST
(
test_rewrites
);
#ifdef MONGOOSE_USE_SSL
RUN_TEST
(
test_ssl
);
#endif
...
...
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