-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add introduce for http-std (#83)
Close #72 --------- Co-authored-by: xihale <[email protected]> Co-authored-by: Jiacai Liu <[email protected]>
- Loading branch information
1 parent
eaaba20
commit 6048579
Showing
4 changed files
with
38 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## http.Server - std | ||
|
||
Starting with release 0.12.0, a very simple implementation of `http.Server` has been introduced. | ||
|
||
```zig | ||
{{#include ../src/05-03.zig }} | ||
``` | ||
|
||
Note: The std implementation exhibits extremely poor performance. If you're planning beyond basic experimentation, consider utilizing alternative libraries such as: | ||
- <https://github.com/karlseguin/http.zig> | ||
- <https://github.com/zigzap/zap> | ||
- <https://github.com/mookums/zzz> |
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,22 @@ | ||
// reference: https://pismice.github.io/HEIG_ZIG/docs/web/std-http/ | ||
const std = @import("std"); | ||
|
||
pub fn main() !void { | ||
const addr = try std.net.Address.parseIp("127.0.0.1", 8080); | ||
var server = try std.net.Address.listen(addr, .{ .reuse_address = true }); | ||
|
||
var buf: [65535]u8 = undefined; | ||
const conn = try server.accept(); | ||
|
||
var client = std.http.Server.init(conn, &buf); | ||
|
||
while (client.state == .ready) { | ||
var request = client.receiveHead() catch |err| switch (err) { | ||
std.http.Server.ReceiveHeadError.HttpConnectionClosing => break, | ||
else => return err, | ||
}; | ||
_ = try request.reader(); | ||
|
||
try request.respond("Hello http.std!", .{}); | ||
} | ||
} |