예제 #1
0
 async def handler(request):
     if request.path == "/1.0.0/application/token":
         assert request.encode().decode() == ACCESS_REQUEST
         response = http.HTTPResponse(200)
         response.json = {"accessToken": "access.token"}
         return response
     else:
         assert request.encode().decode() == LOGIN_REQUEST
         response = http.HTTPResponse(200)
         response.json = {"idToken": "id token"}
         return response
예제 #2
0
 async def handler(request):
     if request.path == "/v6/challenge":
         assert request.encode().decode() == CHALLENGE_REQUEST
         response = http.HTTPResponse(200)
         response.json = {
             "challenge": "vaNgVZZH7gUse0y3t8Cksuln-TAVtvBmcD-ow59qp0E=",
             "data": "dlL7ZBNSLmYo1hUlKYZiUA=="
         }
         return response
     else:
         assert request.encode().decode() == TOKEN_REQUEST
         response = http.HTTPResponse(200)
         response.json = {"device_auth_token": "device token"}
         return response
예제 #3
0
 async def handler(request):
     text = request.encode().decode()
     assert text.startswith(EXPECTED_REQUEST)
     assert text[1378:1388] == "&cert_key="
     response = http.HTTPResponse(200)
     response.json = {"application_auth_token": "application token"}
     return response
예제 #4
0
 async def handler(request):
     assert request.xml.name == "value"
     tree = xml.XMLTree("result")
     tree.text = request.xml.text
     response = http.HTTPResponse(200)
     response.xml = tree
     return response
예제 #5
0
    async def accept_handshake(self):
        logger.debug("Accepting WS handshake")

        self.server_mode = True

        while b"\r\n\r\n" not in self.buffer:
            self.buffer += await self.client.recv()

        index = self.buffer.index(b"\r\n\r\n")
        header = self.buffer[:index + 4]
        self.buffer = self.buffer[index + 4:]

        request = http.HTTPRequest.parse(header)
        if request.method != "GET":
            raise WSError("WS request has unexpected method: %s" %
                          request.method)

        if "Sec-WebSocket-Key" not in request.headers:
            raise WSError("Sec-WebSocket-Key header is missing")
        if "Sec-WebSocket-Protocol" not in request.headers:
            raise WSError("Sec-WebSocket-Protocol header is missing")

        if request.headers["Sec-WebSocket-Protocol"] != self.protocol:
            raise WSError("Sec-WebSocket-Protocol header has unexpected value")

        accept = calculate_key_hash(request.headers["Sec-WebSocket-Key"])

        response = http.HTTPResponse(101)
        response.headers["Connection"] = "upgrade"
        response.headers["Upgrade"] = "WebSocket"
        response.headers["Sec-WebSocket-Accept"] = accept
        response.headers["Sec-WebSocket-Protocol"] = self.protocol
        await self.client.send(response.encode())

        logger.debug("WS handshake succeeded")

        await self.group.spawn(self.process)
예제 #6
0
 async def handler(req):
     response = http.HTTPResponse(404)
     response.body = b"not found"
     return response
예제 #7
0
 async def handler(request):
     assert request.path == "/test/get"
     return http.HTTPResponse(200)
예제 #8
0
 async def handler(request):
     assert request.method == "POST"
     assert request.path == "/test/error"
     status = int(request.headers["X-Status-Code"])
     response = http.HTTPResponse(status)
     return response
예제 #9
0
 async def handler(request):
     assert request.method == "GET"
     assert request.path == "/test/ok"
     response = http.HTTPResponse(200)
     return response
예제 #10
0
 async def handler(request):
     assert request.certificate.subject["CN"] == "testclient"
     return http.HTTPResponse(200)
예제 #11
0
 async def handler(request):
     response = http.HTTPResponse(200)
     response.json = {"result": request.json["value"]}
     return response
예제 #12
0
 async def handler(request):
     response = http.HTTPResponse(200)
     response.form = {"$<result>": request.form["&value"]}
     return response
예제 #13
0
 async def handler(request):
     assert request.text == "+value +=!=?"
     response = http.HTTPResponse(200)
     response.plainform = {"$<result>": request.plainform["+value +"]}
     return response
예제 #14
0
 async def handler(request):
     response = http.HTTPResponse(200)
     response.body = request.body
     return response
예제 #15
0
 async def handler(request):
     assert request.body == b"Hello"
     response = http.HTTPResponse(200)
     response.text = request.text.upper()
     return response
예제 #16
0
 async def handler(request):
     assert request.body == b"abcdef"
     response = http.HTTPResponse(200)
     response.headers["X-Content-Size"] = len(request.body)
     return response