File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change 1+ from lightbug_http.http import HTTPRequest
2+ from lightbug_http.uri import URI
3+ from lightbug_http.sys.client import MojoClient
4+
5+ fn test_request_simple_url (inout client : MojoClient) raises -> None :
6+ """
7+ Test making a simple GET request without parameters.
8+ Validate that we get a 200 OK response.
9+ """
10+ var uri = URI(" http://httpbin.org/" )
11+ var request = HTTPRequest(uri)
12+ var response = client.do(request)
13+
14+ # print status code
15+ print (" Response:" , response.header.status_code())
16+
17+ # print various parsed headers
18+ print (" Header" , response.header.content_length())
19+
20+ # print body
21+ # print(String(response.get_body()))
22+
23+
24+ fn main () raises -> None :
25+ var client = MojoClient()
26+ print (" Testing URL request" )
27+ test_request_simple_url(client)
28+ print (" Done" )
Original file line number Diff line number Diff line change @@ -241,7 +241,10 @@ fn encode(req: HTTPRequest, uri: URI) raises -> Bytes:
241241
242242 _ = builder.write(req.header.method())
243243 _ = builder.write_string(String(" " ))
244- _ = builder.write(uri.request_uri())
244+ if len (uri.request_uri()) > 1 :
245+ _ = builder.write_string(uri.request_uri())
246+ else :
247+ _ = builder.write_string(" /" )
245248 _ = builder.write_string(String(" " ))
246249 _ = builder.write(protocol)
247250 _ = builder.write_string(String(" \r\n " ))
Original file line number Diff line number Diff line change @@ -206,11 +206,11 @@ struct URI:
206206 if path_start >= 0 :
207207 host_and_port = remainder_uri[:path_start]
208208 request_uri = remainder_uri[path_start:]
209+ self .__host = host_and_port[:path_start]._buffer
209210 else :
210211 host_and_port = remainder_uri
211- request_uri = strSlash # Assume root if no path is provided
212-
213- self .__host = host_and_port[:path_start]._buffer
212+ request_uri = strSlash
213+ self .__host = host_and_port._buffer
214214
215215 if is_https:
216216 _ = self .set_scheme(https)
You can’t perform that action at this time.
0 commit comments