1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-14 11:23:02 +02:00

moved http response code validation into a separate function

This commit is contained in:
Gabriel Marinkovic 2019-10-14 17:40:33 +02:00
parent bb37852ba4
commit 04e7f1ecbc

View File

@ -152,15 +152,7 @@ func (drv *Driver) Open(ctx context.Context, params drivers.Params) (drivers.HTM
defer resp.Body.Close()
responseAllowed := false
for _, code := range drv.options.AllowedHTTPCodes {
if resp.StatusCode == code {
responseAllowed = true
break
}
}
if !responseAllowed {
if !drv.responseCodeAllowed(resp) {
return nil, errors.New(resp.Status)
}
@ -186,6 +178,15 @@ func (drv *Driver) Open(ctx context.Context, params drivers.Params) (drivers.HTM
return NewHTMLPage(doc, params.URL, &r, cookies)
}
func (drv *Driver) responseCodeAllowed(resp *stdhttp.Response) bool {
for _, code := range drv.options.AllowedHTTPCodes {
if resp.StatusCode == code {
return true
}
}
return false
}
func (drv *Driver) Parse(_ context.Context, str values.String) (drivers.HTMLPage, error) {
buf := bytes.NewBuffer([]byte(str))