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
|
@ -15,6 +15,8 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
contentTypeHtml = "text/html"
|
contentTypeHtml = "text/html"
|
||||||
|
|
||||||
|
maxBodySizeBytes = 20971520
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultLinkHandler(link string) (*LinkInfo, error) {
|
func defaultLinkHandler(link string) (*LinkInfo, error) {
|
||||||
|
@ -70,7 +72,11 @@ func defaultLinkHandler(link string) (*LinkInfo, error) {
|
||||||
|
|
||||||
switch contentType {
|
switch contentType {
|
||||||
case contentTypeHtml:
|
case contentTypeHtml:
|
||||||
|
if contentLength > 0 && contentLength < maxBodySizeBytes {
|
||||||
err = retrieveHtmlLinkTitle(ret, link)
|
err = retrieveHtmlLinkTitle(ret, link)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
default:
|
default:
|
||||||
ret.Title = fmt.Sprintf("%s (%s, %s)", path.Base(u.Path), contentType, ByteCountDecimal(contentLength))
|
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()
|
defer res.Body.Close()
|
||||||
|
|
||||||
q, err := goquery.NewDocumentFromReader(res.Body)
|
q, err := goquery.NewDocumentFromReader(io.LimitReader(res.Body, maxBodySizeBytes))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue