Skip to content
This repository was archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
🐛 A missing URI path defaults to /.
Browse files Browse the repository at this point in the history
  • Loading branch information
ducdetronquito committed Nov 21, 2020
1 parent 5b66f3c commit fe9bd7e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/connection.zig
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ pub fn Connection(comptime SocketType: type) type {
content = options.content;
}

var _request = try h11.Request.init(method, uri.path, version, headers);
var path = if (uri.path.len != 0) uri.path else "/";

var _request = try h11.Request.init(method, path, version, headers);
defer _request.deinit();

var content_length = try self.frameRequestBody(&_request, content);
Expand Down Expand Up @@ -317,3 +319,18 @@ test "Requesting an IP address and a port should be in HOST headers" {

expect(connection.socket.have_sent("GET / HTTP/1.1\r\nHost: 127.0.0.1:8080\r\n\r\n"));
}


test "Request a URI without path defaults to /" {
const uri = try Uri.parse("http://httpbin.org", false);

var connection = try ConnectionMock.connect(std.testing.allocator, uri);
defer connection.deinit();

try connection.socket.have_received("HTTP/1.1 200 OK\r\n\r\n");

var response = try connection.request(.Get, uri, .{});
defer response.deinit();

expect(connection.socket.have_sent("GET / HTTP/1.1\r\nHost: httpbin.org\r\n\r\n"));
}

0 comments on commit fe9bd7e

Please sign in to comment.