File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,9 @@ cdef class HttpParser:
151
151
def should_keep_alive (self ):
152
152
return bool (cparser.http_should_keep_alive(self ._cparser))
153
153
154
+ def should_upgrade (self ):
155
+ return bool (self ._cparser.upgrade)
156
+
154
157
def feed_data (self , data ):
155
158
cdef:
156
159
size_t data_len
Original file line number Diff line number Diff line change @@ -348,6 +348,26 @@ def test_parser_request_upgrade_1(self):
348
348
b'Host' : b'example.com' ,
349
349
b'Upgrade' : b'WebSocket' })
350
350
351
+ def test_parser_request_upgrade_flag (self ):
352
+ m = mock .Mock ()
353
+ p = httptools .HttpRequestParser (m )
354
+
355
+ def on_headers_complete ():
356
+ self .assertEqual (p .should_upgrade (), False )
357
+
358
+ def on_message_complete ():
359
+ self .assertEqual (p .should_upgrade (), True )
360
+
361
+ m .on_headers_complete = on_headers_complete
362
+ m .on_message_complete = on_message_complete
363
+
364
+ try :
365
+ p .feed_data (UPGRADE_REQUEST1 )
366
+ except httptools .HttpParserUpgrade as ex :
367
+ offset = ex .args [0 ]
368
+ else :
369
+ self .fail ('HttpParserUpgrade was not raised' )
370
+
351
371
def test_parser_request_error_in_on_header (self ):
352
372
class Error (Exception ):
353
373
pass
You can’t perform that action at this time.
0 commit comments