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
50719782
Commit
50719782
authored
Jun 04, 2012
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Corrected should_keep_alive() per bel2s suggestions
parent
89a61e49
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
5 deletions
+45
-5
mongoose.c
mongoose.c
+5
-5
unit_test.c
test/unit_test.c
+40
-0
No files found.
mongoose.c
View file @
50719782
...
...
@@ -827,11 +827,11 @@ static int match_prefix(const char *pattern, int pattern_len, const char *str) {
static
int
should_keep_alive
(
const
struct
mg_connection
*
conn
)
{
const
char
*
http_version
=
conn
->
request_info
.
http_version
;
const
char
*
header
=
mg_get_header
(
conn
,
"Connection"
);
return
(
!
conn
->
must_close
&&
!
conn
->
request_info
.
status_code
!=
401
&&
!
mg_strcasecmp
(
conn
->
ctx
->
config
[
ENABLE_KEEP_ALIVE
],
"yes"
)
&&
(
header
==
NULL
&&
http_version
&&
!
strcmp
(
http_version
,
"1.1"
))
)
||
(
header
!=
NULL
&&
!
mg_strcasecmp
(
header
,
"keep-alive"
));
return
!
(
conn
->
must_close
==
1
||
conn
->
request_info
.
status_code
==
401
||
mg_strcasecmp
(
conn
->
ctx
->
config
[
ENABLE_KEEP_ALIVE
],
"yes"
)
!=
0
||
(
header
!=
NULL
&&
mg_strcasecmp
(
header
,
"keep-alive"
)
!=
0
)
||
(
header
==
NULL
&&
http_version
&&
strcmp
(
http_version
,
"1.1"
)
));
}
static
const
char
*
suggest_connection_header
(
const
struct
mg_connection
*
conn
)
{
...
...
test/unit_test.c
View file @
50719782
#include "mongoose.c"
static
void
test_should_keep_alive
(
void
)
{
struct
mg_connection
conn
;
struct
mg_context
ctx
;
char
req1
[]
=
"GET / HTTP/1.1
\r\n\r\n
"
;
char
req2
[]
=
"GET / HTTP/1.0
\r\n\r\n
"
;
char
req3
[]
=
"GET / HTTP/1.1
\r\n
Connection: close
\r\n\r\n
"
;
char
req4
[]
=
"GET / HTTP/1.1
\r\n
Connection: keep-alive
\r\n\r\n
"
;
memset
(
&
conn
,
0
,
sizeof
(
conn
));
conn
.
ctx
=
&
ctx
;
parse_http_request
(
req1
,
&
conn
.
request_info
);
ctx
.
config
[
ENABLE_KEEP_ALIVE
]
=
"no"
;
assert
(
should_keep_alive
(
&
conn
)
==
0
);
ctx
.
config
[
ENABLE_KEEP_ALIVE
]
=
"yes"
;
assert
(
should_keep_alive
(
&
conn
)
==
1
);
conn
.
must_close
=
1
;
assert
(
should_keep_alive
(
&
conn
)
==
0
);
conn
.
must_close
=
0
;
parse_http_request
(
req2
,
&
conn
.
request_info
);
assert
(
should_keep_alive
(
&
conn
)
==
0
);
parse_http_request
(
req3
,
&
conn
.
request_info
);
assert
(
should_keep_alive
(
&
conn
)
==
0
);
parse_http_request
(
req4
,
&
conn
.
request_info
);
assert
(
should_keep_alive
(
&
conn
)
==
1
);
conn
.
request_info
.
status_code
=
401
;
//assert(should_keep_alive(&conn) == 0);
conn
.
request_info
.
status_code
=
200
;
conn
.
must_close
=
1
;
assert
(
should_keep_alive
(
&
conn
)
==
0
);
}
static
void
test_match_prefix
(
void
)
{
assert
(
match_prefix
(
"/a/"
,
3
,
"/a/b/c"
)
==
3
);
assert
(
match_prefix
(
"/a/"
,
3
,
"/ab/c"
)
==
-
1
);
...
...
@@ -57,5 +96,6 @@ static void test_remove_double_dots() {
int
main
(
void
)
{
test_match_prefix
();
test_remove_double_dots
();
test_should_keep_alive
();
return
0
;
}
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