Multiple headers as tuple
@benoitc 已經在處理了。
開始於 2020年4月17日。
評估
這個 Issue 還沒有評估資料。
描述
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
- 主要語言
- C
- 星號
- 345
- 分支
- 93
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
benoitc/http-parser 的其他 Issue
-
Python 3.12 installation fails可能已有人在做 @s-t-e-v-e-n-k 於 1039 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 38/100
benoitc/http-parser#99 · 1 則留言 · 6 個 reaction ·
-
難度 3/5 1-2 天 新手友好度 45/100
benoitc/http-parser#98 · 1 則留言 · 2 個 reaction ·
-
難度 3/5 1-2 天 新手友好度 50/100
benoitc/http-parser#96 ·
-
Build fails on python3.11可能重新可做 關聯的 PR 已關閉且未合併。 未關閉
難度 2/5 1-3 小時 新手友好度 45/100
benoitc/http-parser#94 · 1 個 reaction ·
-
難度 3/5 1-2 天 新手友好度 30/100
benoitc/http-parser#93 · 1 則留言 · 1 個 reaction ·
查看 benoitc/http-parser 的全部 Issue
相似的 Issue
-
`table_create()` crashes when an `hccalloc()` for the option table fails可能已有人在做 @marinelay 今天認領。 未關閉type: bug
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
bug severity: low
難度 2/5 1-3 小時 新手友好度 78/100
AlessandroSangiuliano/Uros#950 ·
-
ESP32
難度 1/5 1 小時以內 新手友好度 84/100
-
難度 1/5 1-3 小時 新手友好度 82/100
HandBrake/HandBrake#8266 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
saschb2b/Mega-Man-Battle-Network-Cyberworld-Endless#568 ·
維護者通常 1 天內回覆