-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from bgreni/header-refactor
Refactor header parsing and data structure
- Loading branch information
Showing
34 changed files
with
1,139 additions
and
2,326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from lightbug_http.sys.server import SysServer | ||
from lightbug_http.service import TechEmpowerRouter | ||
|
||
|
||
def main(): | ||
try: | ||
var server = SysServer(tcp_keep_alive=True) | ||
var handler = TechEmpowerRouter() | ||
server.listen_and_serve("0.0.0.0:8080", handler) | ||
except e: | ||
print("Error starting server: " + e.__str__()) | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
from lightbug_http import * | ||
from lightbug_http.sys.client import MojoClient | ||
|
||
fn test_request(inout client: MojoClient) raises -> None: | ||
var uri = URI("http://httpbin.org/status/404") | ||
try: | ||
uri.parse() | ||
except e: | ||
print("error parsing uri: " + e.__str__()) | ||
|
||
fn test_request(inout client: MojoClient) raises -> None: | ||
var uri = URI.parse_raises("http://httpbin.org/status/404") | ||
var headers = Header("Host", "httpbin.org") | ||
|
||
var request = HTTPRequest(uri) | ||
var response = client.do(request) | ||
var request = HTTPRequest(uri, headers) | ||
var response = client.do(request^) | ||
|
||
# print status code | ||
print("Response:", response.header.status_code()) | ||
print("Response:", response.status_code) | ||
|
||
# print parsed headers (only some are parsed for now) | ||
print("Content-Type:", to_string(response.header.content_type())) | ||
print("Content-Length", response.header.content_length()) | ||
print("Server:", to_string(response.header.server())) | ||
print("Content-Type:", response.headers["Content-Type"]) | ||
print("Content-Length", response.headers["Content-Length"]) | ||
print("Server:", to_string(response.headers["Server"])) | ||
|
||
print("Is connection set to connection-close? ", response.header.connection_close()) | ||
print( | ||
"Is connection set to connection-close? ", response.connection_close() | ||
) | ||
|
||
# print body | ||
print(to_string(response.get_body_bytes())) | ||
print(to_string(response.body_raw)) | ||
|
||
|
||
fn main() raises -> None: | ||
var client = MojoClient() | ||
test_request(client) | ||
fn main() -> None: | ||
try: | ||
var client = MojoClient() | ||
test_request(client) | ||
except e: | ||
print(e) |
Oops, something went wrong.