-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_http.zig
49 lines (41 loc) · 1.32 KB
/
test_http.zig
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const std = @import("std");
const expect = std.testing.expect;
const mem = std.mem;
const http = @import("http.zig");
test "test get mimetype for path" {
const res = http.mimeForPath("foo/index.html");
try expect(mem.eql(u8, res, "text/html"));
}
test "test unknown file type" {
const res = http.mimeForPath("favicon.ico");
try expect(mem.eql(u8, res, "application/octet-stream"));
}
test "test parsePath" {
const requestLine = "GET /foo.html HTTP/1.1";
const res = try http.parsePath(requestLine);
try expect(mem.eql(u8, res, "/foo.html"));
}
test "test bad method" {
const requestLine = "POST /foo.html HTTP/1.1";
_ = http.parsePath(requestLine) catch |err| {
try expect(err == http.ServeFileError.MethodNotSupported);
return;
};
}
test "test garbo string" {
const requestLine = "Foobar";
_ = http.parsePath(requestLine) catch |err| {
try expect(err == http.ServeFileError.MethodNotSupported);
return;
};
}
test "test parseHeader" {
const header =
"GET / HTTP1.1\r\n" ++
"Host: localhost:8000\r\n" ++
"User-Agent: FooBrowser\r\n" ++
"Accept-Lang: en\r\n";
const res = try http.parseHeader(header);
try expect(mem.eql(u8, res.host, "localhost:8000"));
try expect(mem.eql(u8, res.userAgent, "FooBrowser"));
}