Skip to content

Commit

Permalink
more dev
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Feb 16, 2024
1 parent 0362d8d commit 8b1dd24
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions runtimepy/net/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from typing import Optional, TextIO

# third-party
from svgen.attribute import attributes
from svgen.element import Element
from vcorelib import DEFAULT_ENCODING
from vcorelib.io import ARBITER, JsonObject

Expand All @@ -30,13 +32,30 @@ def json_handler(


def html_handler(stream: TextIO, response: ResponseHeader) -> None:
"""TODO."""
"""Render an HTML document in response to an HTTP request."""

response["Content-Type"] = "text/html; charset={DEFAULT_ENCODING}"

head = Element(
tag="head",
children=[
Element(
tag="meta", attrib=attributes({"charset": DEFAULT_ENCODING})
),
Element(tag="title", text="LET'S GO"),
],
)

body = Element(
tag="body", children=[Element(tag="div", text="Hello, world!")]
)

html = Element(
tag="html", attrib=attributes({"lang": "en"}), children=[head, body]
)

stream.write("<!DOCTYPE html>\n")
stream.write('<html lang="en">\n')
stream.write("<\\html>\n")
html.encode(stream)


class RuntimepyServerConnection(HttpConnection):
Expand All @@ -59,5 +78,6 @@ async def get_handler(
# check mappings

with StringIO() as stream:
json_handler(stream, response, data)
# json_handler(stream, response, data)
html_handler(stream, response)
return stream.getvalue().encode()

0 comments on commit 8b1dd24

Please sign in to comment.