Add maximum body size to html link parsing
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Tyler 2019-10-03 20:05:25 -04:00
parent e50488b364
commit 580a1c2fb0

View File

@ -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