This repository was archived by the owner on Jan 13, 2021. It is now read-only.
File tree 4 files changed +34
-13
lines changed
4 files changed +34
-13
lines changed Original file line number Diff line number Diff line change 1
1
Release History
2
2
===============
3
3
4
+ dev
5
+ ---
6
+
7
+ *Bugfixes *
8
+
9
+ - Overriding HTTP/2 special headers no longer leads to ill-formed header blocks
10
+ with special headers at the end.
11
+
4
12
0.5.0 (2015-10-11)
5
13
------------------
6
14
Original file line number Diff line number Diff line change @@ -184,15 +184,28 @@ def iter_raw(self):
184
184
def replace (self , key , value ):
185
185
"""
186
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.
187
+ method work like ``__setitem__``. Replacing leads to deletion of all
188
+ existing headers with the same name.
189
189
"""
190
- try :
191
- del self [key ]
192
- except KeyError :
193
- pass
190
+ key = to_bytestring (key )
191
+ indices = []
192
+ for (i , (k , v )) in enumerate (self ._items ):
193
+ if _keys_equal (k , key ):
194
+ indices .append (i )
195
+
196
+ # If the key isn't present, this is easy: just append and abort early.
197
+ if not indices :
198
+ self ._items .append ((key , value ))
199
+ return
200
+
201
+ # Delete all but the first. I swear, this is the correct slicing
202
+ # syntax!
203
+ base_index = indices [0 ]
204
+ for i in indices [:0 :- 1 ]:
205
+ self ._items .pop (i )
194
206
195
- self [key ] = value
207
+ del self ._items [base_index ]
208
+ self ._items .insert (base_index , (key , value ))
196
209
197
210
def merge (self , other ):
198
211
"""
Original file line number Diff line number Diff line change @@ -272,8 +272,8 @@ def test_replacing(self):
272
272
273
273
assert list (h .items ()) == [
274
274
(b'name' , b'value' ),
275
- (b'name3' , b'value3' ),
276
275
(b'name2' , b'42' ),
276
+ (b'name3' , b'value3' ),
277
277
(b'name4' , b'other_value' ),
278
278
]
279
279
Original file line number Diff line number Diff line change @@ -122,8 +122,8 @@ def test_putheader_replaces_headers(self):
122
122
assert list (s .headers .items ()) == [
123
123
(b':method' , b'GET' ),
124
124
(b':scheme' , b'https' ),
125
- (b':path' , b'/' ),
126
125
(b':authority' , b'www.example.org' ),
126
+ (b':path' , b'/' ),
127
127
(b'name' , b'value2' ),
128
128
]
129
129
@@ -581,7 +581,7 @@ def test_recv_cb_n_times(self):
581
581
582
582
def consume_single_frame ():
583
583
mutable ['counter' ] += 1
584
-
584
+
585
585
c ._consume_single_frame = consume_single_frame
586
586
c ._recv_cb ()
587
587
@@ -779,7 +779,7 @@ def test_streams_can_replace_none_headers(self):
779
779
(b"name" , b"value" ),
780
780
(b"other_name" , b"other_value" )
781
781
]
782
-
782
+
783
783
def test_stream_opening_sends_headers (self ):
784
784
def data_callback (frame ):
785
785
assert isinstance (frame , HeadersFrame )
@@ -1548,7 +1548,7 @@ def test_connection_error_when_send_out_of_range_frame(self):
1548
1548
class NullEncoder (object ):
1549
1549
@staticmethod
1550
1550
def encode (headers ):
1551
-
1551
+
1552
1552
def to_str (v ):
1553
1553
if is_py2 :
1554
1554
return str (v )
@@ -1557,7 +1557,7 @@ def to_str(v):
1557
1557
v = str (v , 'utf-8' )
1558
1558
return v
1559
1559
1560
- return '\n ' .join ("%s%s" % (to_str (name ), to_str (val ))
1560
+ return '\n ' .join ("%s%s" % (to_str (name ), to_str (val ))
1561
1561
for name , val in headers )
1562
1562
1563
1563
You can’t perform that action at this time.
0 commit comments