31
31
import io
32
32
import gc
33
33
from micropython import const
34
- from adafruit_requests import parse_headers
35
34
import adafruit_esp32spi .adafruit_esp32spi_socket as socket
36
35
37
36
_the_interface = None # pylint: disable=invalid-name
@@ -46,6 +45,22 @@ def set_interface(iface):
46
45
47
46
NO_SOCK_AVAIL = const (255 )
48
47
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
+
49
64
# pylint: disable=invalid-name
50
65
class WSGIServer :
51
66
"""
@@ -99,7 +114,7 @@ def finish_response(self, result):
99
114
:param string result: the data string to send back in the response to the client.
100
115
"""
101
116
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" )
103
118
for header in self ._response_headers :
104
119
response += "{0}: {1}\r \n " .format (* header )
105
120
response += "\r \n "
@@ -159,7 +174,10 @@ def _start_response(self, status, response_headers):
159
174
ex ("header-name", "header value")
160
175
"""
161
176
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
163
181
164
182
def _get_environ (self , client ):
165
183
"""
0 commit comments