Add body size limit
This commit is contained in:
parent
5558c94a57
commit
aae3d75490
1 changed files with 7 additions and 1 deletions
|
@ -22,6 +22,7 @@ import (
|
||||||
// Note: Some websites have a user agent filter.
|
// Note: Some websites have a user agent filter.
|
||||||
const userAgent = "Mozilla/5.0 (like Gecko, like Safari, like Chrome) - Miniflux <https://miniflux.net/>"
|
const userAgent = "Mozilla/5.0 (like Gecko, like Safari, like Chrome) - Miniflux <https://miniflux.net/>"
|
||||||
const requestTimeout = 300
|
const requestTimeout = 300
|
||||||
|
const maxBodySize = 1024 * 1024 * 15
|
||||||
|
|
||||||
// Client is a HTTP Client :)
|
// Client is a HTTP Client :)
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
@ -80,6 +81,10 @@ func (c *Client) executeRequest(request *http.Request) (*Response, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.ContentLength > maxBodySize {
|
||||||
|
return nil, fmt.Errorf("client: response too large (%d bytes)", resp.ContentLength)
|
||||||
|
}
|
||||||
|
|
||||||
response := &Response{
|
response := &Response{
|
||||||
Body: resp.Body,
|
Body: resp.Body,
|
||||||
StatusCode: resp.StatusCode,
|
StatusCode: resp.StatusCode,
|
||||||
|
@ -89,10 +94,11 @@ func (c *Client) executeRequest(request *http.Request) (*Response, error) {
|
||||||
ContentType: resp.Header.Get("Content-Type"),
|
ContentType: resp.Header.Get("Content-Type"),
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Debug("[HttpClient:%s] OriginalURL=%s, StatusCode=%d, ETag=%s, LastModified=%s, EffectiveURL=%s",
|
logger.Debug("[HttpClient:%s] OriginalURL=%s, StatusCode=%d, ContentLength=%d, ETag=%s, LastModified=%s, EffectiveURL=%s",
|
||||||
request.Method,
|
request.Method,
|
||||||
c.url,
|
c.url,
|
||||||
response.StatusCode,
|
response.StatusCode,
|
||||||
|
resp.ContentLength,
|
||||||
response.ETag,
|
response.ETag,
|
||||||
response.LastModified,
|
response.LastModified,
|
||||||
response.EffectiveURL,
|
response.EffectiveURL,
|
||||||
|
|
Loading…
Reference in a new issue