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
415b9d07
Commit
415b9d07
authored
Dec 17, 2013
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python: Refactor class
parent
01266182
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
39 deletions
+31
-39
python/nghttp2.pyx
python/nghttp2.pyx
+31
-39
No files found.
python/nghttp2.pyx
View file @
415b9d07
...
...
@@ -31,7 +31,26 @@ HD_SIDE_RESPONSE = cnghttp2.NGHTTP2_HD_SIDE_RESPONSE
HD_DEFLATE_HD_TABLE_BUFSIZE_MAX
=
4096
cdef
class
HDDeflater
:
cdef
class
_HDContextBase
:
cdef
cnghttp2
.
nghttp2_hd_context
_ctx
def
__init__
(
self
):
pass
def
change_table_size
(
self
,
hd_table_bufsize_max
):
'''Changes header table size to |hd_table_bufsize_max| byte.
An exception will be raised on error.
'''
cdef
int
rv
rv
=
cnghttp2
.
nghttp2_hd_change_table_size
(
&
self
.
_ctx
,
hd_table_bufsize_max
)
if
rv
!=
0
:
raise
Exception
(
_strerror
(
rv
))
cdef
class
HDDeflater
(
_HDContextBase
):
'''Performs header compression. The header compression algorithm has
to know the header set to be compressed is request headers or
response headers. It is indicated by |side| parameter in the
...
...
@@ -57,21 +76,19 @@ cdef class HDDeflater:
'''
cdef
cnghttp2
.
nghttp2_hd_context
_deflater
def
__cinit__
(
self
,
side
,
hd_table_bufsize_max
=
HD_DEFLATE_HD_TABLE_BUFSIZE_MAX
):
rv
=
cnghttp2
.
nghttp2_hd_deflate_init2
(
&
self
.
_
deflater
,
side
,
rv
=
cnghttp2
.
nghttp2_hd_deflate_init2
(
&
self
.
_
ctx
,
side
,
hd_table_bufsize_max
)
if
rv
!=
0
:
raise
Exception
(
_strerror
(
rv
))
def
__init__
(
self
,
side
,
hd_table_bufsize_max
=
HD_DEFLATE_HD_TABLE_BUFSIZE_MAX
):
pass
super
(
HDDeflater
,
self
).
__init__
()
def
__dealloc__
(
self
):
cnghttp2
.
nghttp2_hd_deflate_free
(
&
self
.
_
deflater
)
cnghttp2
.
nghttp2_hd_deflate_free
(
&
self
.
_
ctx
)
def
deflate
(
self
,
headers
):
'''Compresses the |headers|. The |headers| must be sequence of tuple
...
...
@@ -95,7 +112,7 @@ cdef class HDDeflater:
cdef
uint8_t
*
out
=
NULL
cdef
size_t
outcap
=
0
cdef
ssize_t
rv
rv
=
cnghttp2
.
nghttp2_hd_deflate_hd
(
&
self
.
_
deflater
,
&
out
,
&
outcap
,
rv
=
cnghttp2
.
nghttp2_hd_deflate_hd
(
&
self
.
_
ctx
,
&
out
,
&
outcap
,
0
,
nva
,
len
(
headers
))
free
(
nva
)
if
rv
<
0
:
...
...
@@ -107,14 +124,6 @@ cdef class HDDeflater:
cnghttp2
.
nghttp2_free
(
out
)
return
res
def
change_table_size
(
self
,
hd_table_bufsize_max
):
'''Changes header table size to |hd_table_bufsize_max| byte.
An exception will be raised on error.
'''
_hd_change_table_size
(
&
self
.
_deflater
,
hd_table_bufsize_max
)
def
set_no_refset
(
self
,
no_refset
):
'''Tells the compressor not to use reference set if |no_refset| is
nonzero. If |no_refset| is nonzero, on each invocation of
...
...
@@ -122,9 +131,9 @@ cdef class HDDeflater:
reference set.
'''
cnghttp2
.
nghttp2_hd_deflate_set_no_refset
(
&
self
.
_
deflater
,
no_refset
)
cnghttp2
.
nghttp2_hd_deflate_set_no_refset
(
&
self
.
_
ctx
,
no_refset
)
cdef
class
HDInflater
:
cdef
class
HDInflater
(
_HDContextBase
)
:
'''Performs header decompression.
The following example shows how to compress request header sets:
...
...
@@ -136,18 +145,16 @@ cdef class HDInflater:
'''
cdef
cnghttp2
.
nghttp2_hd_context
_inflater
def
__cinit__
(
self
,
side
):
rv
=
cnghttp2
.
nghttp2_hd_inflate_init
(
&
self
.
_
inflater
,
side
)
rv
=
cnghttp2
.
nghttp2_hd_inflate_init
(
&
self
.
_
ctx
,
side
)
if
rv
!=
0
:
raise
Exception
(
_strerror
(
rv
))
def
__init__
(
self
,
side
):
pass
super
(
HDInflater
,
self
).
__init__
()
def
__dealloc__
(
self
):
cnghttp2
.
nghttp2_hd_inflate_free
(
&
self
.
_
inflater
)
cnghttp2
.
nghttp2_hd_inflate_free
(
&
self
.
_
ctx
)
def
inflate
(
self
,
data
):
'''Decompresses the compressed header block |data|. The |data| must be
...
...
@@ -157,7 +164,7 @@ cdef class HDInflater:
cdef
cnghttp2
.
nghttp2_nv
*
nva
cdef
ssize_t
rv
rv
=
cnghttp2
.
nghttp2_hd_inflate_hd
(
&
self
.
_
inflater
,
&
nva
,
rv
=
cnghttp2
.
nghttp2_hd_inflate_hd
(
&
self
.
_
ctx
,
&
nva
,
data
,
len
(
data
))
if
rv
<
0
:
raise
Exception
(
_strerror
(
rv
))
...
...
@@ -166,23 +173,8 @@ cdef class HDInflater:
nva
[
i
].
value
[:
nva
[
i
].
valuelen
])
for
i
in
range
(
rv
)]
finally
:
cnghttp2
.
nghttp2_nv_array_del
(
nva
)
cnghttp2
.
nghttp2_hd_end_headers
(
&
self
.
_
inflater
)
cnghttp2
.
nghttp2_hd_end_headers
(
&
self
.
_
ctx
)
return
res
def
change_table_size
(
self
,
hd_table_bufsize_max
):
'''Changes header table size to |hd_table_bufsize_max| byte.
An exception will be raised on error.
'''
_hd_change_table_size
(
&
self
.
_inflater
,
hd_table_bufsize_max
)
cdef
_hd_change_table_size
(
cnghttp2
.
nghttp2_hd_context
*
context
,
size_t
hd_table_bufsize_max
):
cdef
int
rv
rv
=
cnghttp2
.
nghttp2_hd_change_table_size
(
context
,
hd_table_bufsize_max
)
if
rv
!=
0
:
raise
Exception
(
_strerror
(
rv
))
cdef
_strerror
(
int
liberror_code
):
return
cnghttp2
.
nghttp2_strerror
(
liberror_code
).
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