aboutsummaryrefslogtreecommitdiffhomepage
path: root/reader/subscription
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-02-07 18:47:47 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-02-07 18:47:47 -0800
commit0fb87eba3f763658e3bf864a9cf78adbdae590c6 (patch)
tree45202029a06b2c79c4bce5995d0987bc5e60c012 /reader/subscription
parent1e70ca1a199199853d3ae95c666400a9a70255e2 (diff)
Improve error handling when the response is empty
Diffstat (limited to 'reader/subscription')
-rw-r--r--reader/subscription/finder.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/reader/subscription/finder.go b/reader/subscription/finder.go
index 835991c..8e361b7 100644
--- a/reader/subscription/finder.go
+++ b/reader/subscription/finder.go
@@ -23,6 +23,7 @@ import (
var (
errConnectionFailure = "Unable to open this link: %v"
errUnreadableDoc = "Unable to analyze this page: %v"
+ errEmptyBody = "This web page is empty"
)
// FindSubscriptions downloads and try to find one or more subscriptions from an URL.
@@ -35,13 +36,22 @@ func FindSubscriptions(websiteURL string) (Subscriptions, error) {
return nil, errors.NewLocalizedError(errConnectionFailure, err)
}
+ // Content-Length = -1 when no Content-Length header is sent
+ if response.ContentLength == 0 {
+ return nil, errors.NewLocalizedError(errEmptyBody)
+ }
+
body, err := response.NormalizeBodyEncoding()
if err != nil {
return nil, err
}
var buffer bytes.Buffer
- io.Copy(&buffer, body)
+ size, _ := io.Copy(&buffer, body)
+ if size == 0 {
+ return nil, errors.NewLocalizedError(errEmptyBody)
+ }
+
reader := bytes.NewReader(buffer.Bytes())
if format := feed.DetectFeedFormat(reader); format != feed.FormatUnknown {