This is an automated email from the ASF dual-hosted git repository.
colegreer pushed a commit to branch 3.6-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/3.6-dev by this push:
new 3106c4b605 CTR Fix python headers cannot accept list
3106c4b605 is described below
commit 3106c4b60500d6cae30f7bffef1cbd1bee5dffbb
Author: Cole-Greer <[email protected]>
AuthorDate: Wed Oct 16 14:32:03 2024 -0700
CTR Fix python headers cannot accept list
aiohttp allows for headers to be passed in either as a dict, or as
a list of pairs. However, the way we were adding the user agent header
was imposing an unnecessary restriction which prevented lists from being
used as headers.
---
.../src/main/python/gremlin_python/driver/connection.py | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/gremlin-python/src/main/python/gremlin_python/driver/connection.py
b/gremlin-python/src/main/python/gremlin_python/driver/connection.py
index 789de181d0..9df9dbc6f6 100644
--- a/gremlin-python/src/main/python/gremlin_python/driver/connection.py
+++ b/gremlin-python/src/main/python/gremlin_python/driver/connection.py
@@ -39,9 +39,7 @@ class Connection:
self._inited = False
self._enable_user_agent_on_connect = enable_user_agent_on_connect
if self._enable_user_agent_on_connect:
- if self._headers is None:
- self._headers = dict()
- self._headers[useragent.userAgentHeader] = useragent.userAgent
+ self.__add_header(useragent.userAgentHeader, useragent.userAgent)
def connect(self):
if self._transport:
@@ -94,3 +92,15 @@ class Connection:
break
finally:
self._pool.put_nowait(self)
+
+ def __add_header(self, key, value):
+ if self._headers is None:
+ self._headers = dict()
+ # Headers may be a list of pairs
+ if isinstance(self._headers, list):
+ for pair in self._headers:
+ if pair[0] == key:
+ self._headers.remove(pair)
+ self._headers.append((key, value))
+ else:
+ self._headers[key] = value