Skip to content

Commit 7932d9c

Browse files
committed
uncomment client test
1 parent cf22edc commit 7932d9c

File tree

6 files changed

+24
-25
lines changed

6 files changed

+24
-25
lines changed

lightbug_http/header.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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()

lightbug_http/http.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

lightbug_http/sys/client.mojo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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())

lightbug_http/uri.mojo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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

run_tests.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ from tests.test_io import test_io
22
from tests.test_http import test_http
33
from tests.test_header import test_header
44
from 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

77
fn main() raises:
88
test_io()
99
test_http()
1010
test_header()
1111
test_uri()
12-
# test_client()
12+
test_client()
1313

tests/test_client.mojo

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff 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-
3718
fn 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)

0 commit comments

Comments
 (0)