mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
http: add reset and tries for transfer
This commit is contained in:
@@ -313,7 +313,6 @@ fn continueWithAuth(cmd: anytype) !void {
|
|||||||
errdefer transfer.abortAuthChallenge();
|
errdefer transfer.abortAuthChallenge();
|
||||||
|
|
||||||
// restart the request with the provided credentials.
|
// restart the request with the provided credentials.
|
||||||
// we need to duplicate the cre
|
|
||||||
const arena = transfer.arena.allocator();
|
const arena = transfer.arena.allocator();
|
||||||
transfer.updateCredentials(
|
transfer.updateCredentials(
|
||||||
try std.fmt.allocPrintZ(arena, "{s}:{s}", .{
|
try std.fmt.allocPrintZ(arena, "{s}:{s}", .{
|
||||||
@@ -322,6 +321,7 @@ fn continueWithAuth(cmd: anytype) !void {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
transfer.reset();
|
||||||
try bc.cdp.browser.http_client.process(transfer);
|
try bc.cdp.browser.http_client.process(transfer);
|
||||||
|
|
||||||
if (intercept_state.empty()) {
|
if (intercept_state.empty()) {
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ fn perform(self: *Client, timeout_ms: c_int) !void {
|
|||||||
const transfer = try Transfer.fromEasy(easy);
|
const transfer = try Transfer.fromEasy(easy);
|
||||||
|
|
||||||
// In case of auth challenge
|
// In case of auth challenge
|
||||||
if (transfer._auth_challenge != null) {
|
if (transfer._auth_challenge != null and transfer._tries < 10) { // TODO give a way to configure the number of auth retries.
|
||||||
if (transfer.client.notification) |notification| {
|
if (transfer.client.notification) |notification| {
|
||||||
var wait_for_interception = false;
|
var wait_for_interception = false;
|
||||||
notification.dispatch(.http_request_auth_required, &.{ .transfer = transfer, .wait_for_interception = &wait_for_interception });
|
notification.dispatch(.http_request_auth_required, &.{ .transfer = transfer, .wait_for_interception = &wait_for_interception });
|
||||||
@@ -643,6 +643,21 @@ pub const Transfer = struct {
|
|||||||
_redirecting: bool = false,
|
_redirecting: bool = false,
|
||||||
_auth_challenge: ?AuthChallenge = null,
|
_auth_challenge: ?AuthChallenge = null,
|
||||||
|
|
||||||
|
// number of times the transfer has been tried.
|
||||||
|
// incremented by reset func.
|
||||||
|
_tries: u8 = 0,
|
||||||
|
|
||||||
|
pub fn reset(self: *Transfer) void {
|
||||||
|
self._redirecting = false;
|
||||||
|
self._auth_challenge = null;
|
||||||
|
self._notified_fail = false;
|
||||||
|
self._header_done_called = false;
|
||||||
|
self.response_header = null;
|
||||||
|
self.bytes_received = 0;
|
||||||
|
|
||||||
|
self._tries += 1;
|
||||||
|
}
|
||||||
|
|
||||||
fn deinit(self: *Transfer) void {
|
fn deinit(self: *Transfer) void {
|
||||||
self.req.headers.deinit();
|
self.req.headers.deinit();
|
||||||
if (self._handle) |handle| {
|
if (self._handle) |handle| {
|
||||||
|
|||||||
Reference in New Issue
Block a user