MCPcopy Index your code
hub / github.com/python-websockets/websockets / serve_html

Function serve_html

experiments/authentication/app.py:76–108  ·  view source on GitHub ↗

Basic HTTP server implemented as a process_request hook.

(connection, request)

Source from the content-addressed store, hash-verified

74
75
76async def serve_html(connection, request):
77 """Basic HTTP server implemented as a process_request hook."""
78 user = get_query_param(request.path, "user")
79 path = urllib.parse.urlparse(request.path).path
80 if path == "/":
81 if user is None:
82 page = "index.html"
83 else:
84 page = "test.html"
85 else:
86 page = path[1:]
87
88 try:
89 template = pathlib.Path(__file__).with_name(page)
90 except ValueError:
91 pass
92 else:
93 if template.is_file():
94 body = template.read_bytes()
95 if user is not None:
96 token = create_token(user)
97 body = body.replace(b"TOKEN", token.encode())
98 headers = Headers(
99 {
100 "Date": email.utils.formatdate(usegmt=True),
101 "Connection": "close",
102 "Content-Length": str(len(body)),
103 "Content-Type": CONTENT_TYPES[template.suffix],
104 }
105 )
106 return Response(200, "OK", headers, body)
107
108 return connection.respond(http.HTTPStatus.NOT_FOUND, "Not found\n")
109
110
111async def first_message_handler(websocket):

Callers

nothing calls this directly

Calls 6

HeadersClass · 0.90
ResponseClass · 0.90
get_query_paramFunction · 0.85
create_tokenFunction · 0.85
encodeMethod · 0.45
respondMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…