Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use slices.Contains to simplify a for loop in the dialer #74

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,20 +430,18 @@ func (d *customDialer) readResponse(ctx context.Context, respPipe *io.PipeReader
warcTargetURIChannel <- warcTargetURI

// If the HTTP status code is to be excluded as per client's settings, we stop here
for i := 0; i < len(d.client.skipHTTPStatusCodes); i++ {
if d.client.skipHTTPStatusCodes[i] == resp.StatusCode {
err = resp.Body.Close()
if err != nil {
return fmt.Errorf("readResponse: response code was blocked by config url and closing body failed: %s", err.Error())
}

err = responseRecord.Content.Close()
if err != nil {
return fmt.Errorf("readResponse: response code was blocked by config url and closing content failed: %s", err.Error())
}
if len(d.client.skipHTTPStatusCodes) > 0 && slices.Contains(d.client.skipHTTPStatusCodes, resp.StatusCode) {
err = resp.Body.Close()
if err != nil {
return fmt.Errorf("readResponse: response code was blocked by config url and closing body failed: %s", err.Error())
}

return fmt.Errorf("readResponse: response code was blocked by config url: '%s'", warcTargetURI)
err = responseRecord.Content.Close()
if err != nil {
return fmt.Errorf("readResponse: response code was blocked by config url and closing content failed: %s", err.Error())
}

return fmt.Errorf("readResponse: response code was blocked by config url: '%s'", warcTargetURI)
}

// Calculate the WARC-Payload-Digest
Expand Down
Loading