File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -159,7 +159,12 @@ def parse(
159
159
raise NotImplementedError ("transfer codings aren't supported" )
160
160
161
161
if "Content-Length" in headers :
162
- raise ValueError ("unsupported request body" )
162
+ content_length = headers ["Content-Length" ]
163
+ if content_length != "0" :
164
+ raise ValueError (
165
+ f"unsupported request body as 'Content-Length' is "
166
+ f"non-zero: { content_length } "
167
+ )
163
168
164
169
return cls (path , headers )
165
170
Original file line number Diff line number Diff line change @@ -83,9 +83,27 @@ def test_parse_body(self):
83
83
next (self .parse ())
84
84
self .assertEqual (
85
85
str (raised .exception ),
86
- "unsupported request body" ,
86
+ "unsupported request body as 'Content-Length' is non-zero: 3 " ,
87
87
)
88
88
89
+ def test_parse_body_content_length_zero (self ):
90
+ # Example from the protocol overview in RFC 6455
91
+ self .reader .feed_data (
92
+ b"GET /chat HTTP/1.1\r \n "
93
+ b"Host: server.example.com\r \n "
94
+ b"Upgrade: websocket\r \n "
95
+ b"Connection: Upgrade\r \n "
96
+ b"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r \n "
97
+ b"Origin: http://example.com\r \n "
98
+ b"Sec-WebSocket-Protocol: chat, superchat\r \n "
99
+ b"Sec-WebSocket-Version: 13\r \n "
100
+ b"Content-Length: 0\r \n "
101
+ b"\r \n "
102
+ )
103
+ request = self .assertGeneratorReturns (self .parse ())
104
+ self .assertEqual (request .path , "/chat" )
105
+ self .assertEqual (request .headers ["Content-Length" ], "0" )
106
+
89
107
def test_parse_body_with_transfer_encoding (self ):
90
108
self .reader .feed_data (b"GET / HTTP/1.1\r \n Transfer-Encoding: compress\r \n \r \n " )
91
109
with self .assertRaises (NotImplementedError ) as raised :
You can’t perform that action at this time.
0 commit comments