diff --git a/default.go b/default.go index 26cb016..47481c7 100644 --- a/default.go +++ b/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