| ... | @@ -19,6 +19,7 @@ test { try httpbinMethod(.http, .POST); } | ... | @@ -19,6 +19,7 @@ test { try httpbinMethod(.http, .POST); } |
| 19 | test { try httpbinMethod(.http, .PUT); } | 19 | test { try httpbinMethod(.http, .PUT); } |
| 20 | test { try httpbinMethod(.http, .PATCH); } | 20 | test { try httpbinMethod(.http, .PATCH); } |
| 21 | test { try httpbinMethod(.http, .DELETE); } | 21 | test { try httpbinMethod(.http, .DELETE); } |
| | 22 | test { try httpbinUserAgent(.http); } |
| 22 | // zig fmt: on | 23 | // zig fmt: on |
| 23 | | 24 | |
| 24 | fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void { | 25 | fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void { |
| ... | @@ -35,3 +36,17 @@ fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void { | ... | @@ -35,3 +36,17 @@ fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void { |
| 35 | defer doc.release(); | 36 | defer doc.release(); |
| 36 | try expect(doc.root.object().getS("url")).toEqualString(url); | 37 | try expect(doc.root.object().getS("url")).toEqualString(url); |
| 37 | } | 38 | } |
| | 39 | fn httpbinUserAgent(comptime scheme: Scheme) !void { |
| | 40 | const allocator = std.testing.allocator; |
| | 41 | const url = @tagName(scheme) ++ "://httpbin.org/user-agent"; |
| | 42 | var req = try http.open(allocator, .GET, url); |
| | 43 | defer req.close(allocator); |
| | 44 | try req.writeUA(); |
| | 45 | try req.send(); |
| | 46 | try expect(req.status).toEqual(.ok); |
| | 47 | const doc = try json.parse(allocator, "httpbinMethod", &req, .{ .support_trailing_commas = false, .maximum_depth = 2 }); |
| | 48 | defer doc.deinit(allocator); |
| | 49 | doc.acquire(); |
| | 50 | defer doc.release(); |
| | 51 | try expect(doc.root.object().getS("user-agent")).toEqualString("WIP https://github.com/nektro/zig-net-http"); |
| | 52 | } |