forked from Lightbug-HQ/lightbug_http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.mojo
29 lines (22 loc) · 961 Bytes
/
client.mojo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from lightbug_http.http import HTTPRequest, encode
from lightbug_http.header import RequestHeader
from lightbug_http.uri import URI
from lightbug_http.sys.client import MojoClient
fn test_request(inout client: MojoClient) raises -> None:
var uri = URI("http://httpbin.org/status/404")
var request = HTTPRequest(uri)
var response = client.do(request)
# print status code
print("Response:", response.header.status_code())
# print raw headers
# print("Headers:", response.header.headers())
# print parsed headers (only some are parsed for now)
print("Content-Type:", String(response.header.content_type()))
print("Content-Length", response.header.content_length())
print("Connection:", response.header.connection_close())
print("Server:", String(response.header.server()))
# print body
print(String(response.get_body()))
fn main() raises -> None:
var client = MojoClient()
test_request(client)