File tree Expand file tree Collapse file tree 6 files changed +24
-25
lines changed Expand file tree Collapse file tree 6 files changed +24
-25
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ struct Headers(Formattable, Stringable):
7676 var first_byte = r.peek()
7777 if not first_byte:
7878 raise Error(" Failed to read first byte from response header" )
79-
79+
8080 var first = r.read_word()
8181 r.increment()
8282 var second = r.read_word()
Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ struct HTTPResponse(Formattable, Stringable):
175175 protocol = protocol,
176176 status_code = int (status_code),
177177 status_text = status_text)
178-
178+
179179 try :
180180 response.read_body(reader)
181181 return response
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ struct MojoClient(Client):
9595
9696 var new_buf = Bytes(capacity = default_buffer_size)
9797 var bytes_recv = conn.read(new_buf)
98-
98+
9999 if bytes_recv == 0 :
100100 conn.close()
101101
@@ -104,4 +104,5 @@ struct MojoClient(Client):
104104 except e:
105105 conn.close()
106106 raise e
107+ print (" should not reach here" )
107108 return HTTPResponse(Bytes())
Original file line number Diff line number Diff line change @@ -42,6 +42,18 @@ struct URI:
4242 u._parse()
4343 return u
4444
45+ fn __init__ (inout self ) -> None :
46+ self .__path_original = " /"
47+ self .scheme = " "
48+ self .path = " /"
49+ self .query_string = " "
50+ self .__hash = " "
51+ self .host = " "
52+ self .full_uri = " "
53+ self .request_uri = " "
54+ self .username = " "
55+ self .password = " "
56+
4557 fn __init__ (
4658 inout self ,
4759 uri : String
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ from tests.test_io import test_io
22from tests.test_http import test_http
33from tests.test_header import test_header
44from tests.test_uri import test_uri
5- # from tests.test_client import test_client # TODO : fix, this currently gives a compilation error
5+ from tests.test_client import test_client
66
77fn main () raises :
88 test_io()
99 test_http()
1010 test_header()
1111 test_uri()
12- # test_client()
12+ test_client()
1313
Original file line number Diff line number Diff line change @@ -15,31 +15,17 @@ def test_client():
1515 test_mojo_client_lightbug_external_req(mojo_client)
1616
1717
18- # fn test_mojo_client_lightbug(client: MojoClient) raises:
19- # var res = client.do(
20- # HTTPRequest(
21- # uri = URI(default_server_conn_string),
22- # body_bytes = bytes("Hello world!"),
23- # headers = GetRequestHeaders,
24- # protocol = "GET",
25- # request
26- # )
27- # )
28- # testing.assert_equal(
29- # String(res.body_raw[0:112]),
30- # String(
31- # "HTTP/1.1 200 OK\r\nServer: lightbug_http\r\nContent-Type:"
32- # " text/plain\r\nContent-Length: 12\r\nConnection: close\r\nDate: "
33- # ),
34- # )
35-
36-
3718fn test_mojo_client_lightbug_external_req (client : MojoClient) raises :
3819 var req = HTTPRequest(
39- URI(" http://grandinnerastoundingspell.neverssl.com/online/" ),
20+ uri = URI .parse(" httpbin.org/status/200" )[URI ],
21+ headers = Header(" Connection" , " keep-alive" ),
22+ protocol = " GET" ,
4023 )
24+ print (" parsed uri: " , req.uri.host)
25+ print (" parsed path: " , req.uri.path)
4126 try :
4227 var res = client.do(req)
4328 testing.assert_equal(res.status_code, 200 )
29+
4430 except e:
4531 print (e)
You can’t perform that action at this time.
0 commit comments