mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
First-pass websocket client handshake
This commit is contained in:
parent
b66be24149
commit
65f04bf4d1
@ -7,7 +7,7 @@ import time
|
||||
import copy
|
||||
import abc
|
||||
import contrib.pyparsing as pp
|
||||
from netlib import http_status, tcp, http_uastrings
|
||||
from netlib import http_status, tcp, http_uastrings, websockets
|
||||
|
||||
import utils
|
||||
|
||||
@ -1006,6 +1006,13 @@ class Request(_Message):
|
||||
|
||||
def resolve(self, settings, **kwargs):
|
||||
tokens = self.tokens[:]
|
||||
if self.method.string().lower() == "ws":
|
||||
tokens[0] = Method("get")
|
||||
for i in websockets.client_handshake_headers().lst:
|
||||
if not utils.get_header(i[0], self.headers):
|
||||
tokens.append(
|
||||
Header(ValueLiteral(i[0]), ValueLiteral(i[1]))
|
||||
)
|
||||
if not self.raw:
|
||||
if not utils.get_header("Content-Length", self.headers):
|
||||
if self.body:
|
||||
@ -1063,7 +1070,7 @@ class WebsocketFrame(_Message):
|
||||
atom = pp.MatchFirst(parts)
|
||||
resp = pp.And(
|
||||
[
|
||||
pp.Literal("ws"),
|
||||
pp.Literal("wf"),
|
||||
Sep,
|
||||
pp.ZeroOrMore(Sep + atom)
|
||||
]
|
||||
|
@ -600,6 +600,11 @@ class TestRequest:
|
||||
r = parse_request("GET:@100").freeze({})
|
||||
assert len(r.spec()) > 100
|
||||
|
||||
def test_websocket(self):
|
||||
r = parse_request('ws:"/foo"')
|
||||
res = r.resolve({})
|
||||
assert utils.get_header("upgrade", res.headers)
|
||||
|
||||
|
||||
class TestWriteValues:
|
||||
def test_send_chunk(self):
|
||||
|
Loading…
Reference in New Issue
Block a user