Multiple headers as tuple
@benoitc đang làm issue này rồi.
Từ ngày 17/4/2020.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Hi,
This little patch introduces a new optional behavior wherby values of multiple headers are returned as a tuple rather than as a comma delimited string. The comma delimited string really doesn't work for cookies where comma is part of the cookie definition.
From f30d048134717d657ab519771a28588e1c3aafcc Mon Sep 17 00:00:00 2001
Date: Mon, 26 Dec 2016 18:57:36 +0000
Subject: [PATCH] New feature: if multiple headers are found, report them as tuple rather than comma joined string
---
http_parser/parser.pyx | 21 +++++++++++++++++++--
http_parser/pyparser.py | 13 ++++++++++---
2 files changed, 29 insertions(+), 5 deletions(-)
mode change 100644 => 100755 http_parser/parser.pyx
mode change 100644 => 100755 http_parser/pyparser.py
diff --git a/http_parser/parser.pyx b/http_parser/parser.pyx
old mode 100644
new mode 100755
index 2ca92d7..94c7ba4
--- a/http_parser/parser.pyx
+++ b/http_parser/parser.pyx
@@ -97,9 +97,24 @@ cdef int on_header_value_cb(http_parser *parser, char *at,
if res._last_field in res.headers:
hval = res.headers[res._last_field]
if not res._last_was_value:
- header_value = "%s, %s" % (hval, header_value)
+ if res.multiple_headers_as_tuple:
+ if type(hval)!=tuple:
+ tmp=(hval,)
+ header_value=tmp+(header_value,)
+ else:
+ header_value = "%s, %s" % (hval, header_value)
else:
header_value = "%s %s" % (hval, header_value)
+
+ #if name in self._headers:
+ # if self.multiple_headers_as_tuple:
+ # if type(self._headers[name])!=tuple:
+ # value=(self._headers[name])
+ # value+=(value,)
+ # else:
+ # value = "%s, %s" % (self._headers[name], value)
+
+
# add to headers
res.headers[res._last_field] = header_value
@@ -170,12 +185,14 @@ def get_errno_description(errno):
class _ParserData(object):
- def __init__(self, decompress=False, header_only=False):
+ def __init__(self, decompress=False, header_only=False,multiple_headers_as_tuple=False):
self.url = ""
self.body = []
self.headers = IOrderedDict()
self.header_only = header_only
+ self.multiple_headers_as_tuple=multiple_headers_as_tuple
+
self.decompress = decompress
self.decompressobj = None
self._decompress_first_try = True
diff --git a/http_parser/pyparser.py b/http_parser/pyparser.py
old mode 100644
new mode 100755
index 835ca34..93e9457
--- a/http_parser/pyparser.py
+++ b/http_parser/pyparser.py
@@ -39,9 +39,10 @@ class InvalidChunkSize(Exception):
class HttpParser(object):
- def __init__(self, kind=2, decompress=False):
+ def __init__(self, kind=2, decompress=False,multiple_headers_as_tuple=False):
self.kind = kind
self.decompress = decompress
+ self.multiple_headers_as_tuple=multiple_headers_as_tuple
# errors vars
self.errno = None
@@ -355,9 +356,15 @@ class HttpParser(object):
value.append(curr)
value = ''.join(value).rstrip()
- # multiple headers
+
+
if name in self._headers:
- value = "%s, %s" % (self._headers[name], value)
+ if self.multiple_headers_as_tuple:
+ if type(self._headers[name])!=tuple:
+ tmp=(self._headers[name],)
+ value=tmp+(value,)
+ else:
+ value = "%s, %s" % (self._headers[name], value)
# store new header value
self._headers[name] = value
--
2.7.4
- Ngôn ngữ chính
- C
- Star
- 345
- Fork
- 93
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của benoitc/http-parser
-
Python 3.12 installation failsCó thể đã có người làm @s-t-e-v-e-n-k đã nhận 1039 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 38/100
benoitc/http-parser#99 · 1 bình luận · 6 reaction ·
-
Support for python 3.11Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
benoitc/http-parser#98 · 1 bình luận · 2 reaction ·
-
Access to Trailer fieldsĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 50/100
benoitc/http-parser#96 ·
-
Build fails on python3.11Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
benoitc/http-parser#94 · 1 reaction ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
benoitc/http-parser#93 · 1 bình luận · 1 reaction ·
Tất cả issue của benoitc/http-parser
Issue tương tự
-
`table_create()` crashes when an `hccalloc()` for the option table failsCó thể đã có người làm @marinelay đã nhận hôm nay. Đang mởtype: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug severity: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AlessandroSangiuliano/Uros#950 ·
-
ESP32
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
HandBrake/HandBrake#8266 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Disable touch control settingĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
saschb2b/Mega-Man-Battle-Network-Cyberworld-Endless#568 ·
Maintainer thường phản hồi trong vòng 1 ngày