88from logging import getLogger
99from typing import Callable , Literal , cast , overload
1010
11+ from asgi_tools import ResponseHTML
1112from asgiref import typing as asgi_types
1213from typing_extensions import Unpack
1314
1415from reactpy import html
1516from reactpy .asgi .middleware import ReactPyMiddleware
16- from reactpy .asgi .utils import (
17- dict_to_byte_list ,
18- http_response ,
19- import_dotted_path ,
20- vdom_head_to_html ,
21- )
17+ from reactpy .asgi .utils import import_dotted_path , vdom_head_to_html
2218from reactpy .types import (
2319 AsgiApp ,
2420 AsgiHttpApp ,
@@ -40,7 +36,7 @@ def __init__(
4036 self ,
4137 root_component : RootComponentConstructor ,
4238 * ,
43- http_headers : dict [str , str | int ] | None = None ,
39+ http_headers : dict [str , str ] | None = None ,
4440 html_head : VdomDict | None = None ,
4541 html_lang : str = "en" ,
4642 ** settings : Unpack [ReactPyConfig ],
@@ -182,44 +178,33 @@ async def __call__(
182178
183179 # Response headers for `index.html` responses
184180 request_headers = dict (scope ["headers" ])
185- response_headers : dict [str , str | int ] = {
181+ response_headers : dict [str , str ] = {
186182 "etag" : self ._etag ,
187183 "last-modified" : self ._last_modified ,
188184 "access-control-allow-origin" : "*" ,
189185 "cache-control" : "max-age=60, public" ,
190- "content-length" : len (self ._cached_index_html ),
186+ "content-length" : str ( len (self ._cached_index_html ) ),
191187 "content-type" : "text/html; charset=utf-8" ,
192188 ** self .parent .extra_headers ,
193189 }
194190
195191 # Browser is asking for the headers
196192 if scope ["method" ] == "HEAD" :
197- return await http_response (
198- send = send ,
199- method = scope ["method" ],
200- headers = dict_to_byte_list (response_headers ),
201- )
193+ response = ResponseHTML ("" , headers = response_headers )
194+ return await response (scope , receive , send ) # type: ignore
202195
203196 # Browser already has the content cached
204197 if (
205198 request_headers .get (b"if-none-match" ) == self ._etag .encode ()
206199 or request_headers .get (b"if-modified-since" ) == self ._last_modified .encode ()
207200 ):
208201 response_headers .pop ("content-length" )
209- return await http_response (
210- send = send ,
211- method = scope ["method" ],
212- code = 304 ,
213- headers = dict_to_byte_list (response_headers ),
214- )
202+ response = ResponseHTML ("" , headers = response_headers , status_code = 304 )
203+ return await response (scope , receive , send ) # type: ignore
215204
216205 # Send the index.html
217- await http_response (
218- send = send ,
219- method = scope ["method" ],
220- message = self ._cached_index_html ,
221- headers = dict_to_byte_list (response_headers ),
222- )
206+ response = ResponseHTML (self ._cached_index_html , headers = response_headers )
207+ await response (scope , receive , send ) # type: ignore
223208
224209 def process_index_html (self ) -> None :
225210 """Process the index.html and store the results in memory."""
0 commit comments