webseed: Handle http response status codes

This commit is contained in:
Matt Joiner 2020-10-15 12:42:27 +11:00
parent 4a4cb5dc58
commit 30d0b5b9c7
1 changed files with 9 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package webseed
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/http"
@ -91,8 +92,14 @@ func recvPartResult(buf io.Writer, part requestPart) error {
return result.err
}
defer result.resp.Body.Close()
if part.e.Start != 0 && result.resp.StatusCode != http.StatusPartialContent {
return fmt.Errorf("expected partial content response got %v", result.resp.StatusCode)
switch result.resp.StatusCode {
case http.StatusPartialContent:
case http.StatusOK:
if part.e.Start != 0 {
return errors.New("got status ok but request was at offset")
}
default:
return fmt.Errorf("unhandled response status code (%v)", result.resp.StatusCode)
}
copied, err := io.Copy(buf, result.resp.Body)
if err != nil {