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
6ef9b743
Commit
6ef9b743
authored
Dec 09, 2012
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shrpx: Color HTTP headers in console log
parent
9b1f36d2
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
62 additions
and
7 deletions
+62
-7
src/shrpx_http.cc
src/shrpx_http.cc
+32
-0
src/shrpx_http.h
src/shrpx_http.h
+3
-0
src/shrpx_http_downstream_connection.cc
src/shrpx_http_downstream_connection.cc
+9
-1
src/shrpx_https_upstream.cc
src/shrpx_https_upstream.cc
+11
-2
src/shrpx_log.h
src/shrpx_log.h
+3
-0
src/shrpx_spdy_downstream_connection.cc
src/shrpx_spdy_downstream_connection.cc
+1
-1
src/shrpx_spdy_session.cc
src/shrpx_spdy_session.cc
+1
-1
src/shrpx_spdy_upstream.cc
src/shrpx_spdy_upstream.cc
+2
-2
No files found.
src/shrpx_http.cc
View file @
6ef9b743
...
...
@@ -27,6 +27,7 @@
#include <sstream>
#include "shrpx_config.h"
#include "shrpx_log.h"
#include "util.h"
#include "uri.h"
...
...
@@ -141,6 +142,37 @@ void capitalize(std::string& s, size_t offset)
}
}
std
::
string
colorizeHeaders
(
const
char
*
hdrs
)
{
std
::
string
nhdrs
;
const
char
*
p
=
strchr
(
hdrs
,
'\n'
);
if
(
!
p
)
{
// Not valid HTTP header
return
hdrs
;
}
nhdrs
.
append
(
hdrs
,
p
+
1
);
++
p
;
while
(
1
)
{
const
char
*
np
=
strchr
(
p
,
':'
);
if
(
!
np
)
{
nhdrs
.
append
(
p
);
break
;
}
nhdrs
+=
TTY_HTTP_HD
;
nhdrs
.
append
(
p
,
np
);
nhdrs
+=
TTY_RST
;
p
=
np
;
np
=
strchr
(
p
,
'\n'
);
if
(
!
np
)
{
nhdrs
.
append
(
p
);
break
;
}
nhdrs
.
append
(
p
,
np
+
1
);
p
=
np
+
1
;
}
return
nhdrs
;
}
}
// namespace http
}
// namespace shrpx
src/shrpx_http.h
View file @
6ef9b743
...
...
@@ -41,6 +41,9 @@ std::string modify_location_header_value(const std::string& uri);
void
capitalize
(
std
::
string
&
s
,
size_t
offset
);
// Adds ANSI color codes to HTTP headers |hdrs|.
std
::
string
colorizeHeaders
(
const
char
*
hdrs
);
}
// namespace http
}
// namespace shrpx
...
...
src/shrpx_http_downstream_connection.cc
View file @
6ef9b743
...
...
@@ -182,8 +182,16 @@ int HttpDownstreamConnection::push_request_headers()
hdrs
+=
"
\r\n
"
;
if
(
ENABLE_LOG
)
{
const
char
*
hdrp
;
std
::
string
nhdrs
;
if
(
get_config
()
->
tty
)
{
nhdrs
=
http
::
colorizeHeaders
(
hdrs
.
c_str
());
hdrp
=
nhdrs
.
c_str
();
}
else
{
hdrp
=
hdrs
.
c_str
();
}
DCLOG
(
INFO
,
this
)
<<
"HTTP request headers. stream_id="
<<
downstream_
->
get_stream_id
()
<<
"
\n
"
<<
hdrs
;
<<
downstream_
->
get_stream_id
()
<<
"
\n
"
<<
hdrp
;
}
evbuffer
*
output
=
bufferevent_get_output
(
bev_
);
int
rv
;
...
...
src/shrpx_https_upstream.cc
View file @
6ef9b743
...
...
@@ -149,7 +149,8 @@ int htp_hdrs_completecb(http_parser *htp)
<<
downstream
->
get_request_minor
()
<<
"
\n
"
;
const
Headers
&
headers
=
downstream
->
get_request_headers
();
for
(
size_t
i
=
0
;
i
<
headers
.
size
();
++
i
)
{
ss
<<
headers
[
i
].
first
<<
": "
<<
headers
[
i
].
second
<<
"
\n
"
;
ss
<<
TTY_HTTP_HD
<<
headers
[
i
].
first
<<
TTY_RST
<<
": "
<<
headers
[
i
].
second
<<
"
\n
"
;
}
ULOG
(
INFO
,
upstream
)
<<
"HTTP request headers
\n
"
<<
ss
.
str
();
}
...
...
@@ -631,7 +632,15 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
hdrs
+=
"
\r\n
"
;
hdrs
+=
"
\r\n
"
;
if
(
ENABLE_LOG
)
{
ULOG
(
INFO
,
this
)
<<
"HTTP response headers
\n
"
<<
hdrs
;
const
char
*
hdrp
;
std
::
string
nhdrs
;
if
(
get_config
()
->
tty
)
{
nhdrs
=
http
::
colorizeHeaders
(
hdrs
.
c_str
());
hdrp
=
nhdrs
.
c_str
();
}
else
{
hdrp
=
hdrs
.
c_str
();
}
ULOG
(
INFO
,
this
)
<<
"HTTP response headers
\n
"
<<
hdrp
;
}
evbuffer
*
output
=
bufferevent_get_output
(
handler_
->
get_bev
());
if
(
evbuffer_add
(
output
,
hdrs
.
c_str
(),
hdrs
.
size
())
!=
0
)
{
...
...
src/shrpx_log.h
View file @
6ef9b743
...
...
@@ -89,6 +89,9 @@ private:
static
int
severity_thres_
;
};
#define TTY_HTTP_HD (get_config()->tty ? "\033[1;34m" : "")
#define TTY_RST (get_config()->tty ? "\033[0m" : "")
}
// namespace shrpx
#endif // SHRPX_LOG_H
src/shrpx_spdy_downstream_connection.cc
View file @
6ef9b743
...
...
@@ -294,7 +294,7 @@ int SpdyDownstreamConnection::push_request_headers()
if
(
ENABLE_LOG
)
{
std
::
stringstream
ss
;
for
(
size_t
i
=
0
;
nv
[
i
];
i
+=
2
)
{
ss
<<
nv
[
i
]
<<
": "
<<
nv
[
i
+
1
]
<<
"
\n
"
;
ss
<<
TTY_HTTP_HD
<<
nv
[
i
]
<<
TTY_RST
<<
": "
<<
nv
[
i
+
1
]
<<
"
\n
"
;
}
DCLOG
(
INFO
,
this
)
<<
"HTTP request headers
\n
"
<<
ss
.
str
();
}
...
...
src/shrpx_spdy_session.cc
View file @
6ef9b743
...
...
@@ -592,7 +592,7 @@ void on_ctrl_recv_callback
if
(
ENABLE_LOG
)
{
std
::
stringstream
ss
;
for
(
size_t
i
=
0
;
nv
[
i
];
i
+=
2
)
{
ss
<<
nv
[
i
]
<<
": "
<<
nv
[
i
+
1
]
<<
"
\n
"
;
ss
<<
TTY_HTTP_HD
<<
nv
[
i
]
<<
TTY_RST
<<
": "
<<
nv
[
i
+
1
]
<<
"
\n
"
;
}
SSLOG
(
INFO
,
spdy
)
<<
"HTTP response headers. stream_id="
<<
frame
->
syn_reply
.
stream_id
...
...
src/shrpx_spdy_upstream.cc
View file @
6ef9b743
...
...
@@ -198,7 +198,7 @@ void on_ctrl_recv_callback
if
(
ENABLE_LOG
)
{
std
::
stringstream
ss
;
for
(
size_t
i
=
0
;
nv
[
i
];
i
+=
2
)
{
ss
<<
nv
[
i
]
<<
": "
<<
nv
[
i
+
1
]
<<
"
\n
"
;
ss
<<
TTY_HTTP_HD
<<
nv
[
i
]
<<
TTY_RST
<<
": "
<<
nv
[
i
+
1
]
<<
"
\n
"
;
}
ULOG
(
INFO
,
upstream
)
<<
"HTTP request headers. stream_id="
<<
downstream
->
get_stream_id
()
...
...
@@ -777,7 +777,7 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream)
if
(
ENABLE_LOG
)
{
std
::
stringstream
ss
;
for
(
size_t
i
=
0
;
nv
[
i
];
i
+=
2
)
{
ss
<<
nv
[
i
]
<<
": "
<<
nv
[
i
+
1
]
<<
"
\n
"
;
ss
<<
TTY_HTTP_HD
<<
nv
[
i
]
<<
TTY_RST
<<
": "
<<
nv
[
i
+
1
]
<<
"
\n
"
;
}
ULOG
(
INFO
,
this
)
<<
"HTTP response headers. stream_id="
<<
downstream
->
get_stream_id
()
<<
"
\n
"
...
...
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