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
bddfa3c0
Commit
bddfa3c0
authored
Dec 18, 2013
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python: Add method to get/print header table
parent
415b9d07
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
1 deletion
+55
-1
python/cnghttp2.pxd
python/cnghttp2.pxd
+14
-1
python/nghttp2.pyx
python/nghttp2.pyx
+41
-0
No files found.
python/cnghttp2.pxd
View file @
bddfa3c0
...
...
@@ -42,12 +42,22 @@ cdef extern from 'nghttp2_frame.h':
cdef
extern
from
'nghttp2_hd.h'
:
# This is macro
int
NGHTTP2_HD_ENTRY_OVERHEAD
ctypedef
enum
nghttp2_hd_side
:
NGHTTP2_HD_SIDE_REQUEST
NGHTTP2_HD_SIDE_RESPONSE
ctypedef
enum
nghttp2_hd_flags
:
NGHTTP2_HD_FLAG_REFSET
ctypedef
struct
nghttp2_hd_entry
:
nghttp2_nv
nv
uint8_t
flags
ctypedef
struct
nghttp2_hd_context
:
pass
size_t
deflate_hd_tablelen
int
nghttp2_hd_deflate_init2
(
nghttp2_hd_context
*
deflater
,
nghttp2_hd_side
side
,
...
...
@@ -77,3 +87,6 @@ cdef extern from 'nghttp2_hd.h':
uint8_t
*
input
,
size_t
inlen
)
int
nghttp2_hd_end_headers
(
nghttp2_hd_context
*
deflater_or_inflater
)
nghttp2_hd_entry
*
nghttp2_hd_table_get
(
nghttp2_hd_context
*
context
,
size_t
index
)
python/nghttp2.pyx
View file @
bddfa3c0
...
...
@@ -31,6 +31,18 @@ HD_SIDE_RESPONSE = cnghttp2.NGHTTP2_HD_SIDE_RESPONSE
HD_DEFLATE_HD_TABLE_BUFSIZE_MAX
=
4096
HD_ENTRY_OVERHEAD
=
cnghttp2
.
NGHTTP2_HD_ENTRY_OVERHEAD
class
HDTableEntry
:
def
__init__
(
self
,
name
,
value
,
ref
):
self
.
name
=
name
self
.
value
=
value
self
.
ref
=
ref
def
space
(
self
):
return
len
(
self
.
name
)
+
len
(
self
.
value
)
+
HD_ENTRY_OVERHEAD
cdef
class
_HDContextBase
:
cdef
cnghttp2
.
nghttp2_hd_context
_ctx
...
...
@@ -50,6 +62,18 @@ cdef class _HDContextBase:
if
rv
!=
0
:
raise
Exception
(
_strerror
(
rv
))
def
get_hd_table
(
self
):
'''Returns copy of current dynamic header table.'''
cdef
int
length
=
self
.
_ctx
.
deflate_hd_tablelen
cdef
cnghttp2
.
nghttp2_hd_entry
*
entry
res
=
[]
for
i
in
range
(
length
):
entry
=
cnghttp2
.
nghttp2_hd_table_get
(
&
self
.
_ctx
,
i
)
res
.
append
(
HDTableEntry
(
entry
.
nv
.
name
[:
entry
.
nv
.
namelen
],
entry
.
nv
.
value
[:
entry
.
nv
.
valuelen
],
(
entry
.
flags
&
cnghttp2
.
NGHTTP2_HD_FLAG_REFSET
)
!=
0
))
return
res
cdef
class
HDDeflater
(
_HDContextBase
):
'''Performs header compression. The header compression algorithm has
to know the header set to be compressed is request headers or
...
...
@@ -178,3 +202,20 @@ cdef class HDInflater(_HDContextBase):
cdef
_strerror
(
int
liberror_code
):
return
cnghttp2
.
nghttp2_strerror
(
liberror_code
).
decode
(
'utf-8'
)
def
print_hd_table
(
hdtable
):
'''Convenient function to print |hdtable| to the standard output. This
function does not work if header name/value cannot be decoded using
UTF-8 encoding.
s=N means the entry occupies N bytes in header table. if r=y, then
the entry is in the reference set.
'''
idx
=
0
for
entry
in
hdtable
:
idx
+=
1
print
(
'[{}] (s={}) (r={}) {}: {}'
.
format
(
idx
,
entry
.
space
(),
'y'
if
entry
.
ref
else
'n'
,
entry
.
name
.
decode
(
'utf-8'
),
entry
.
value
.
decode
(
'utf-8'
)))
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