3131import io
3232import gc
3333from micropython import const
34- from adafruit_requests import parse_headers
3534import adafruit_esp32spi .adafruit_esp32spi_socket as socket
3635
3736_the_interface = None # pylint: disable=invalid-name
@@ -46,6 +45,22 @@ def set_interface(iface):
4645
4746NO_SOCK_AVAIL = const (255 )
4847
48+
49+ def parse_headers (client ):
50+ """
51+ Parses the header portion of an HTTP request from the socket.
52+ Expects first line of HTTP request to have been read already.
53+ """
54+ headers = {}
55+ while True :
56+ line = str (client .readline (), "utf-8" )
57+ if not line :
58+ break
59+ title , content = line .split (":" , 1 )
60+ headers [title .strip ().lower ()] = content .strip ()
61+ return headers
62+
63+
4964# pylint: disable=invalid-name
5065class WSGIServer :
5166 """
@@ -99,7 +114,7 @@ def finish_response(self, result):
99114 :param string result: the data string to send back in the response to the client.
100115 """
101116 try :
102- response = "HTTP/1.1 {0}\r \n " .format (self ._response_status )
117+ response = "HTTP/1.1 {0}\r \n " .format (self ._response_status or "500 ISE" )
103118 for header in self ._response_headers :
104119 response += "{0}: {1}\r \n " .format (* header )
105120 response += "\r \n "
@@ -159,7 +174,10 @@ def _start_response(self, status, response_headers):
159174 ex ("header-name", "header value")
160175 """
161176 self ._response_status = status
162- self ._response_headers = [("Server" , "esp32WSGIServer" )] + response_headers
177+ self ._response_headers = [
178+ ("Server" , "esp32WSGIServer" ),
179+ ("Connection" , "close" ),
180+ ] + response_headers
163181
164182 def _get_environ (self , client ):
165183 """
0 commit comments