| ... | @@ -4,6 +4,7 @@ const json = @import("json"); | ... | @@ -4,6 +4,7 @@ const json = @import("json"); |
| 4 | const expect = @import("expect").expect; | 4 | const expect = @import("expect").expect; |
| 5 | const extras = @import("extras"); | 5 | const extras = @import("extras"); |
| 6 | const Scheme = enum { http }; | 6 | const Scheme = enum { http }; |
| | 7 | const Compression = enum { deflate, gzip, brotli }; |
| 7 | | 8 | |
| 8 | test { | 9 | test { |
| 9 | const allocator = std.testing.allocator; | 10 | const allocator = std.testing.allocator; |
| ... | @@ -20,6 +21,9 @@ test { try httpbinMethod(.http, .PUT); } | ... | @@ -20,6 +21,9 @@ test { try httpbinMethod(.http, .PUT); } |
| 20 | test { try httpbinMethod(.http, .PATCH); } | 21 | test { try httpbinMethod(.http, .PATCH); } |
| 21 | test { try httpbinMethod(.http, .DELETE); } | 22 | test { try httpbinMethod(.http, .DELETE); } |
| 22 | test { try httpbinUserAgent(.http); } | 23 | test { try httpbinUserAgent(.http); } |
| | 24 | test { try httpbinCompresssed(.http, .deflate); } |
| | 25 | test { try httpbinCompresssed(.http, .gzip); } |
| | 26 | test { try httpbinCompresssed(.http, .brotli); } |
| 23 | // zig fmt: on | 27 | // zig fmt: on |
| 24 | | 28 | |
| 25 | fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void { | 29 | fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void { |
| ... | @@ -50,3 +54,16 @@ fn httpbinUserAgent(comptime scheme: Scheme) !void { | ... | @@ -50,3 +54,16 @@ fn httpbinUserAgent(comptime scheme: Scheme) !void { |
| 50 | defer doc.release(); | 54 | defer doc.release(); |
| 51 | try expect(doc.root.object().getS("user-agent")).toEqualString("WIP https://github.com/nektro/zig-net-http"); | 55 | try expect(doc.root.object().getS("user-agent")).toEqualString("WIP https://github.com/nektro/zig-net-http"); |
| 52 | } | 56 | } |
| | 57 | fn httpbinCompresssed(comptime scheme: Scheme, comptime compression: Compression) !void { |
| | 58 | const allocator = std.testing.allocator; |
| | 59 | const url = @tagName(scheme) ++ "://httpbin.org/" ++ @tagName(compression); |
| | 60 | var req = try http.open(allocator, .GET, url); |
| | 61 | defer req.close(); |
| | 62 | try req.writeUA(); |
| | 63 | try req.send(); |
| | 64 | try expect(req.status).toEqual(.ok); |
| | 65 | try expect(req.headers.find("content-encoding")).toEqualString(switch (compression) { |
| | 66 | else => |tag| @tagName(tag), |
| | 67 | .brotli => "br", |
| | 68 | }); |
| | 69 | } |