File: _proto_http_async.py

package info (click to toggle)
electrum 4.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 35,248 kB
  • sloc: python: 222,785; sh: 165; java: 73; javascript: 10; makefile: 9
file content (27 lines) | stat: -rw-r--r-- 773 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from ._proto_http import ConnectRequest, ConnectResponse
from ._stream_async import AsyncSocketStream


class HttpProto:
    def __init__(self, stream: AsyncSocketStream, dest_host, dest_port,
                 username=None, password=None):

        self._dest_host = dest_host
        self._dest_port = dest_port
        self._username = username
        self._password = password

        self._stream = stream

    async def negotiate(self):
        request = ConnectRequest(
            host=self._dest_host,
            port=self._dest_port,
            login=self._username,
            password=self._password,
        )

        await self._stream.write_all(bytes(request))

        response = ConnectResponse(await self._stream.read())
        response.validate()