Skip to content

Commit

Permalink
Merge pull request #74 from vbanos/list-contains
Browse files Browse the repository at this point in the history
Use slices.Contains to simplify a for loop in the dialer
  • Loading branch information
CorentinB authored Feb 2, 2025
2 parents fdb0696 + 6a30ddb commit c6a4cdb
Showing 1 changed file with 10 additions and 12 deletions.
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

0 comments on commit c6a4cdb

Please sign in to comment.