Compare commits

...

3 Commits

Author SHA1 Message Date
gvilums
2efd10b4df Apply formatting changes 2024-05-31 23:25:28 +00:00
Georgijs Vilums
e3c096565b add more reliable test 2024-05-31 16:07:43 -07:00
Georgijs Vilums
e394db4cc1 fix flaky tls test 2024-05-31 15:06:43 -07:00
3 changed files with 65 additions and 1 deletions

View File

@@ -1701,7 +1701,7 @@ pub const Fetch = struct {
defer task.mutex.unlock();
log("callback success {} has_more {} bytes {}", .{ result.isSuccess(), result.has_more, result.body.?.list.items.len });
task.result = result;
task.result.merge(result);
// metadata should be provided only once so we preserve it until we consume it
if (result.metadata) |metadata| {

View File

@@ -3106,6 +3106,54 @@ pub const HTTPClientResult = struct {
};
}
};
pub fn merge(this: *HTTPClientResult, other: HTTPClientResult) void {
if (other.body != null) {
if (this.body == null) {
this.body = other.body;
} else {
if (comptime Environment.allow_assert) {
bun.assert(this.body == other.body);
}
}
}
if (!other.has_more) {
this.has_more = false;
}
if (other.fail != null) {
this.fail = other.fail;
}
if (other.metadata != null) {
if (this.metadata == null) {
this.metadata = other.metadata;
} else {
if (comptime Environment.allow_assert) {
@panic("duplicate http metadata");
}
}
}
if (other.body_size != .unknown) {
this.body_size = other.body_size;
}
if (other.redirected) {
this.redirected = true;
}
if (other.certificate_info != null) {
if (this.certificate_info == null) {
this.certificate_info = other.certificate_info;
} else {
if (comptime Environment.allow_assert) {
@panic("duplicate http certificate info");
}
}
}
}
};
pub fn toResult(this: *HTTPClient) HTTPClientResult {

View File

@@ -77,6 +77,22 @@ it("fetch with valid tls and non-native checkServerIdentity should work", async
expect(count).toBe(2);
});
it("not skip verification when doing a lot of requests", async () => {
let count = 0;
let promise = fetch(`https://example.com`, {
tls: {
checkServerIdentity() {
++count;
},
},
});
let wait_until = performance.now() + 1000;
while (performance.now() < wait_until) {}
await promise;
expect(count).toBe(1);
});
it("fetch with rejectUnauthorized: false should not call checkServerIdentity", async () => {
let count = 0;