| ... | @@ -2,6 +2,7 @@ const std = @import("std"); | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | const http = @import("http"); | 2 | const http = @import("http"); |
| 3 | const json = @import("json"); | 3 | const json = @import("json"); |
| 4 | const expect = @import("expect").expect; | 4 | const expect = @import("expect").expect; |
| | 5 | const extras = @import("extras"); |
| 5 | const Scheme = enum { http }; | 6 | const Scheme = enum { http }; |
| 6 | | 7 | |
| 7 | test { | 8 | test { |
| ... | @@ -13,18 +14,22 @@ test { | ... | @@ -13,18 +14,22 @@ test { |
| 13 | } | 14 | } |
| 14 | | 15 | |
| 15 | // zig fmt: off | 16 | // zig fmt: off |
| 16 | test { try httpbinMethodGet(.http); } | 17 | test { try httpbinMethod(.http, .GET); } |
| | 18 | test { try httpbinMethod(.http, .POST); } |
| | 19 | test { try httpbinMethod(.http, .PUT); } |
| | 20 | test { try httpbinMethod(.http, .PATCH); } |
| | 21 | test { try httpbinMethod(.http, .DELETE); } |
| 17 | // zig fmt: on | 22 | // zig fmt: on |
| 18 | | 23 | |
| 19 | fn httpbinMethodGet(comptime scheme: Scheme) !void { | 24 | fn httpbinMethod(comptime scheme: Scheme, comptime method: http.Method) !void { |
| 20 | const allocator = std.testing.allocator; | 25 | const allocator = std.testing.allocator; |
| 21 | const url = @tagName(scheme) ++ "://httpbin.org/get"; | 26 | const url = @tagName(scheme) ++ "://httpbin.org/" ++ comptime extras.asciiLowerComptime(@tagName(method)); |
| 22 | var req = try http.open(allocator, .GET, url); | 27 | var req = try http.open(allocator, method, url); |
| 23 | defer req.close(allocator); | 28 | defer req.close(allocator); |
| 24 | try req.writeUA(); | 29 | try req.writeUA(); |
| 25 | try req.send(); | 30 | try req.send(); |
| 26 | try expect(req.status).toEqual(.ok); | 31 | try expect(req.status).toEqual(.ok); |
| 27 | const doc = try json.parse(allocator, "httpbinMethodGet", &req, .{ .support_trailing_commas = false, .maximum_depth = 2 }); | 32 | const doc = try json.parse(allocator, "httpbinMethod", &req, .{ .support_trailing_commas = false, .maximum_depth = 2 }); |
| 28 | defer doc.deinit(allocator); | 33 | defer doc.deinit(allocator); |
| 29 | doc.acquire(); | 34 | doc.acquire(); |
| 30 | defer doc.release(); | 35 | defer doc.release(); |