nuclei/v2/pkg/protocols/offlinehttp/read_response.go

24 lines
565 B
Go
Raw Normal View History

package offlinehttp
import (
"bufio"
2021-02-08 19:08:35 +05:30
"errors"
"net/http"
"strings"
)
// readResponseFromString reads a raw http response from a string.
func readResponseFromString(data string) (*http.Response, error) {
var final string
if strings.HasPrefix(data, "HTTP/") {
final = data
} else {
2021-02-08 19:08:35 +05:30
lastIndex := strings.LastIndex(data, "HTTP/")
if lastIndex == -1 {
return nil, errors.New("malformed raw http response")
}
2021-02-26 13:13:11 +05:30
final = data // choose last http/ in case of it being later.
}
return http.ReadResponse(bufio.NewReader(strings.NewReader(final)), nil)
}