Add maximum body size to html link parsing
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
e50488b364
commit
580a1c2fb0
10
default.go
10
default.go
|
@ -15,6 +15,8 @@ import (
|
|||
|
||||
const (
|
||||
contentTypeHtml = "text/html"
|
||||
|
||||
maxBodySizeBytes = 20971520
|
||||
)
|
||||
|
||||
func defaultLinkHandler(link string) (*LinkInfo, error) {
|
||||
|
@ -70,7 +72,11 @@ func defaultLinkHandler(link string) (*LinkInfo, error) {
|
|||
|
||||
switch contentType {
|
||||
case contentTypeHtml:
|
||||
err = retrieveHtmlLinkTitle(ret, link)
|
||||
if contentLength > 0 && contentLength < maxBodySizeBytes {
|
||||
err = retrieveHtmlLinkTitle(ret, link)
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
ret.Title = fmt.Sprintf("%s (%s, %s)", path.Base(u.Path), contentType, ByteCountDecimal(contentLength))
|
||||
}
|
||||
|
@ -123,7 +129,7 @@ func retrieveHtmlLinkTitle(i *LinkInfo, link string) error {
|
|||
|
||||
defer res.Body.Close()
|
||||
|
||||
q, err := goquery.NewDocumentFromReader(res.Body)
|
||||
q, err := goquery.NewDocumentFromReader(io.LimitReader(res.Body, maxBodySizeBytes))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue