Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 7e671d0

Browse files
committed
Merge pull request #189 from tbetbetbe/simple-http20-concurrency
Simple http20 concurrency
2 parents 46f4b1b + 78e06a7 commit 7e671d0

File tree

9 files changed

+447
-122
lines changed

9 files changed

+447
-122
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Cory Benfield
3+
Copyright (c) 2014 Cory Benfield, Google Inc
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

hyper/common/headers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ def iter_raw(self):
181181
for item in self._items:
182182
yield item
183183

184+
def replace(self, key, value):
185+
"""
186+
Replace existing header with new value. If header doesn't exist this
187+
method work like ``__setitem__``. Replacing leads to deletion of all
188+
exsiting headers with the same name.
189+
"""
190+
try:
191+
del self[key]
192+
except KeyError:
193+
pass
194+
195+
self[key] = value
196+
184197
def merge(self, other):
185198
"""
186199
Merge another header set or any other dict-like into this one.

hyper/common/util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
"""
88
from hyper.compat import unicode, bytes, imap
99
from ..packages.rfc3986.uri import URIReference
10+
from ..compat import is_py3
1011
import re
1112

13+
1214
def to_bytestring(element):
1315
"""
1416
Converts a single string to a bytestring, encoding via UTF-8 if needed.
@@ -28,6 +30,7 @@ def to_bytestring_tuple(*x):
2830
"""
2931
return tuple(imap(to_bytestring, x))
3032

33+
3134
def to_host_port_tuple(host_port_str, default_port=80):
3235
"""
3336
Converts the given string containing a host and possibly a port
@@ -48,3 +51,10 @@ def to_host_port_tuple(host_port_str, default_port=80):
4851
port = int(uri.port)
4952

5053
return (host, port)
54+
55+
56+
def to_native_string(string, encoding='utf-8'):
57+
if isinstance(string, str):
58+
return string
59+
60+
return string.decode(encoding) if is_py3 else string.encode(encoding)

0 commit comments

Comments
 (0)