Skip to content

Commit

Permalink
Fixes #1426
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Nov 9, 2022
1 parent 0fd7d3a commit cb41d77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/bun.js/webcore/response.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5187,7 +5187,7 @@ pub const Request = struct {
};
}

pub fn writeFormat(this: *const Request, formatter: *JSC.Formatter, writer: anytype, comptime enable_ansi_colors: bool) !void {
pub fn writeFormat(this: *Request, formatter: *JSC.Formatter, writer: anytype, comptime enable_ansi_colors: bool) !void {
const Writer = @TypeOf(writer);
try formatter.writeIndent(Writer, writer);
try writer.print("Request ({}) {{\n", .{bun.fmt.size(this.body.slice().len)});
Expand All @@ -5204,7 +5204,9 @@ pub const Request = struct {

try formatter.writeIndent(Writer, writer);
try writer.writeAll("url: \"");
try this.ensureURL();
try writer.print(comptime Output.prettyFmt("<r><b>{s}<r>", enable_ansi_colors), .{this.url});

try writer.writeAll("\"");
if (this.body == .Blob) {
try writer.writeAll("\n");
Expand Down Expand Up @@ -5376,6 +5378,7 @@ pub const Request = struct {

return 0;
}

pub fn ensureURL(this: *Request) !void {
if (this.url.len > 0) return;

Expand Down
21 changes: 19 additions & 2 deletions test/bun.js/serve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,24 @@ it("should work for a file", async () => {
},
});
const response = await fetch(`http://${server.hostname}:${server.port}`);
console.log(response);
expect(await response.text()).toBe(textToExpect);
server.stop();
});

it("request.url should log successfully", async () => {
const fixture = resolve(import.meta.dir, "./fetch.js.txt");
const textToExpect = readFileSync(fixture, "utf-8");
var expected;
const server = serve({
port: port++,
fetch(req) {
expect(Bun.inspect(req).includes(expected)).toBe(true);
return new Response(file(fixture));
},
});
expected = `http://${server.hostname}:${server.port}/helloooo`;
const response = await fetch(expected);
expect(response.url).toBe(expected);
expect(await response.text()).toBe(textToExpect);
server.stop();
});
Expand Down Expand Up @@ -206,7 +223,7 @@ describe("streaming", () => {
var server;
try {
var pass = false;
var err = { name: '', message: '' };
var err = { name: "", message: "" };
server = serve({
port: port++,
development: false,
Expand Down

0 comments on commit cb41d77

Please sign in to comment.