Fixed crash with non-http response

dev
Ice3man543 2021-02-08 19:08:35 +05:30
parent 2a049778cd
commit 10ba90cb31
1 changed files with 6 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package offlinehttp
import (
"bufio"
"errors"
"net/http"
"strings"
)
@ -12,7 +13,11 @@ func readResponseFromString(data string) (*http.Response, error) {
if strings.HasPrefix(data, "HTTP/") {
final = data
} else {
final = data[strings.LastIndex(data, "HTTP/"):] // choose last http/ in case of it being later.
lastIndex := strings.LastIndex(data, "HTTP/")
if lastIndex == -1 {
return nil, errors.New("malformed raw http response")
}
final = data[:] // choose last http/ in case of it being later.
}
return http.ReadResponse(bufio.NewReader(strings.NewReader(final)), nil)
}