mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-16 11:37:36 +02:00
moved http response code validation into a separate function
This commit is contained in:
parent
bb37852ba4
commit
04e7f1ecbc
@ -152,15 +152,7 @@ func (drv *Driver) Open(ctx context.Context, params drivers.Params) (drivers.HTM
|
|||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
responseAllowed := false
|
if !drv.responseCodeAllowed(resp) {
|
||||||
for _, code := range drv.options.AllowedHTTPCodes {
|
|
||||||
if resp.StatusCode == code {
|
|
||||||
responseAllowed = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !responseAllowed {
|
|
||||||
return nil, errors.New(resp.Status)
|
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)
|
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) {
|
func (drv *Driver) Parse(_ context.Context, str values.String) (drivers.HTMLPage, error) {
|
||||||
buf := bytes.NewBuffer([]byte(str))
|
buf := bytes.NewBuffer([]byte(str))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user