Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
a61ca763
Commit
a61ca763
authored
Mar 04, 2014
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpd: Add -e option to toggle gzipped error response
parent
749cc08f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
23 deletions
+37
-23
src/HttpServer.cc
src/HttpServer.cc
+30
-22
src/HttpServer.h
src/HttpServer.h
+1
-0
src/nghttpd.cc
src/nghttpd.cc
+6
-1
No files found.
src/HttpServer.cc
View file @
a61ca763
...
...
@@ -74,7 +74,8 @@ Config::Config()
verbose
(
false
),
daemon
(
false
),
verify_client
(
false
),
no_tls
(
false
)
no_tls
(
false
),
error_gzip
(
false
)
{}
Request
::
Request
(
int32_t
stream_id
)
...
...
@@ -671,30 +672,37 @@ void prepare_status_response(Request *req, Http2Handler *hd,
int
pipefd
[
2
];
if
(
status
==
STATUS_304
||
pipe
(
pipefd
)
==
-
1
)
{
hd
->
submit_response
(
status
,
req
->
stream_id
,
0
);
}
else
{
std
::
stringstream
ss
;
ss
<<
"<html><head><title>"
<<
status
<<
"</title></head><body>"
<<
"<h1>"
<<
status
<<
"</h1>"
<<
"<hr>"
<<
"<address>"
<<
NGHTTPD_SERVER
<<
" at port "
<<
hd
->
get_config
()
->
port
<<
"</address>"
<<
"</body></html>"
;
std
::
string
body
=
ss
.
str
();
return
;
}
std
::
string
body
;
body
.
reserve
(
256
);
body
=
"<html><head><title>"
;
body
+=
status
;
body
+=
"</title></head><body><h1>"
;
body
+=
status
;
body
+=
"</h1><hr><address>"
;
body
+=
NGHTTPD_SERVER
;
body
+=
" at port "
;
body
+=
util
::
utos
(
hd
->
get_config
()
->
port
);
body
+=
"</address>"
;
body
+=
"</body></html>"
;
if
(
hd
->
get_config
()
->
error_gzip
)
{
gzFile
write_fd
=
gzdopen
(
pipefd
[
1
],
"w"
);
gzwrite
(
write_fd
,
body
.
c_str
(),
body
.
size
());
gzclose
(
write_fd
);
close
(
pipefd
[
1
]);
req
->
file
=
pipefd
[
0
];
nghttp2_data_provider
data_prd
;
data_prd
.
source
.
fd
=
pipefd
[
0
];
data_prd
.
read_callback
=
file_read_callback
;
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
headers
;
headers
.
emplace_back
(
"content-encoding"
,
"gzip"
);
headers
.
emplace_back
(
"content-type"
,
"text/html; charset=UTF-8"
);
hd
->
submit_response
(
status
,
req
->
stream_id
,
headers
,
&
data_prd
);
}
}
else
{
write
(
pipefd
[
1
],
body
.
c_str
(),
body
.
size
());
}
close
(
pipefd
[
1
]);
req
->
file
=
pipefd
[
0
];
nghttp2_data_provider
data_prd
;
data_prd
.
source
.
fd
=
pipefd
[
0
];
data_prd
.
read_callback
=
file_read_callback
;
std
::
vector
<
std
::
pair
<
std
::
string
,
std
::
string
>>
headers
;
headers
.
emplace_back
(
"content-encoding"
,
"gzip"
);
headers
.
emplace_back
(
"content-type"
,
"text/html; charset=UTF-8"
);
hd
->
submit_response
(
status
,
req
->
stream_id
,
headers
,
&
data_prd
);
}
}
// namespace
...
...
src/HttpServer.h
View file @
a61ca763
...
...
@@ -64,6 +64,7 @@ struct Config {
bool
daemon
;
bool
verify_client
;
bool
no_tls
;
bool
error_gzip
;
Config
();
};
...
...
src/nghttpd.cc
View file @
a61ca763
...
...
@@ -134,6 +134,7 @@ void print_help(std::ostream& out)
<<
" -n, --workers=<CORE>
\n
"
<<
" Set the number of worker threads.
\n
"
<<
" Default: 1
\n
"
<<
" -e, --error-gzip Make error response gzipped.
\n
"
<<
" --version Display version information and exit.
\n
"
<<
" -h, --help Display this help and exit.
\n
"
<<
std
::
endl
;
...
...
@@ -156,13 +157,14 @@ int main(int argc, char **argv)
{
"push"
,
required_argument
,
nullptr
,
'p'
},
{
"padding"
,
required_argument
,
nullptr
,
'b'
},
{
"workers"
,
required_argument
,
nullptr
,
'n'
},
{
"error-gzip"
,
no_argument
,
nullptr
,
'e'
},
{
"no-tls"
,
no_argument
,
&
flag
,
1
},
{
"color"
,
no_argument
,
&
flag
,
2
},
{
"version"
,
no_argument
,
&
flag
,
3
},
{
nullptr
,
0
,
nullptr
,
0
}
};
int
option_index
=
0
;
int
c
=
getopt_long
(
argc
,
argv
,
"DVb:c:d:hn:p:v"
,
long_options
,
int
c
=
getopt_long
(
argc
,
argv
,
"DVb:c:d:
e
hn:p:v"
,
long_options
,
&
option_index
);
char
*
end
;
if
(
c
==
-
1
)
{
...
...
@@ -181,6 +183,9 @@ int main(int argc, char **argv)
case
'd'
:
config
.
htdocs
=
optarg
;
break
;
case
'e'
:
config
.
error_gzip
=
true
;
break
;
case
'n'
:
errno
=
0
;
config
.
num_worker
=
strtoul
(
optarg
,
&
end
,
10
);
...
...
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