Add content length check when refreshing feeds
This commit is contained in:
parent
c57cafbef2
commit
7d278d49f1
8 changed files with 43 additions and 23 deletions
|
@ -86,12 +86,13 @@ func (c *Client) executeRequest(request *http.Request) (*Response, error) {
|
|||
}
|
||||
|
||||
response := &Response{
|
||||
Body: resp.Body,
|
||||
StatusCode: resp.StatusCode,
|
||||
EffectiveURL: resp.Request.URL.String(),
|
||||
LastModified: resp.Header.Get("Last-Modified"),
|
||||
ETag: resp.Header.Get("ETag"),
|
||||
ContentType: resp.Header.Get("Content-Type"),
|
||||
Body: resp.Body,
|
||||
StatusCode: resp.StatusCode,
|
||||
EffectiveURL: resp.Request.URL.String(),
|
||||
LastModified: resp.Header.Get("Last-Modified"),
|
||||
ETag: resp.Header.Get("ETag"),
|
||||
ContentType: resp.Header.Get("Content-Type"),
|
||||
ContentLength: resp.ContentLength,
|
||||
}
|
||||
|
||||
logger.Debug("[HttpClient:%s] OriginalURL=%s, StatusCode=%d, ContentLength=%d, ETag=%s, LastModified=%s, EffectiveURL=%s",
|
||||
|
|
|
@ -13,12 +13,13 @@ import (
|
|||
|
||||
// Response wraps a server response.
|
||||
type Response struct {
|
||||
Body io.Reader
|
||||
StatusCode int
|
||||
EffectiveURL string
|
||||
LastModified string
|
||||
ETag string
|
||||
ContentType string
|
||||
Body io.Reader
|
||||
StatusCode int
|
||||
EffectiveURL string
|
||||
LastModified string
|
||||
ETag string
|
||||
ContentType string
|
||||
ContentLength int64
|
||||
}
|
||||
|
||||
// HasServerFailure returns true if the status code represents a failure.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2018-01-04 18:06:27.675886358 -0800 PST m=+0.027242794
|
||||
// 2018-01-04 18:29:14.775838828 -0800 PST m=+0.007352060
|
||||
|
||||
package locale
|
||||
|
||||
|
@ -212,12 +212,13 @@ var translations = map[string]string{
|
|||
"Save article": "Sauvegarder l'article",
|
||||
"There is already someone associated with this provider!": "Il y a déjà quelqu'un d'associé avec ce provider !",
|
||||
"There is already someone else with the same Fever username!": "Il y a déjà quelqu'un d'autre avec le même nom d'utilisateur Fever !",
|
||||
"Mark all as read": "Tout marquer comme lu"
|
||||
"Mark all as read": "Tout marquer comme lu",
|
||||
"This feed is empty": "Cet abonnement est vide"
|
||||
}
|
||||
`,
|
||||
}
|
||||
|
||||
var translationsChecksums = map[string]string{
|
||||
"en_US": "6fe95384260941e8a5a3c695a655a932e0a8a6a572c1e45cb2b1ae8baa01b897",
|
||||
"fr_FR": "d68bc2178505410615aa2624b3efbf704f80c17a8024e2866d11c3abda587de7",
|
||||
"fr_FR": "888baaeba8cee020f0cf77db7bad9960e9b640277d042029cafb41e72e13566e",
|
||||
}
|
||||
|
|
|
@ -196,5 +196,6 @@
|
|||
"Save article": "Sauvegarder l'article",
|
||||
"There is already someone associated with this provider!": "Il y a déjà quelqu'un d'associé avec ce provider !",
|
||||
"There is already someone else with the same Fever username!": "Il y a déjà quelqu'un d'autre avec le même nom d'utilisateur Fever !",
|
||||
"Mark all as read": "Tout marquer comme lu"
|
||||
"Mark all as read": "Tout marquer comme lu",
|
||||
"This feed is empty": "Cet abonnement est vide"
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ var (
|
|||
errNotFound = "Feed %d not found"
|
||||
errEncoding = "Unable to normalize encoding: %v."
|
||||
errCategoryNotFound = "Category not found for this user."
|
||||
errEmptyFeed = "This feed is empty"
|
||||
)
|
||||
|
||||
// Handler contains all the logic to create and refresh feeds.
|
||||
|
@ -50,6 +51,11 @@ func (h *Handler) CreateFeed(userID, categoryID int64, url string, crawler bool)
|
|||
return nil, errors.NewLocalizedError(errServerFailure, response.StatusCode)
|
||||
}
|
||||
|
||||
// Content-Length = -1 when no Content-Length header is sent
|
||||
if response.ContentLength == 0 {
|
||||
return nil, errors.NewLocalizedError(errEmptyFeed)
|
||||
}
|
||||
|
||||
if h.store.FeedURLExists(userID, response.EffectiveURL) {
|
||||
return nil, errors.NewLocalizedError(errDuplicate, response.EffectiveURL)
|
||||
}
|
||||
|
@ -133,6 +139,16 @@ func (h *Handler) RefreshFeed(userID, feedID int64) error {
|
|||
|
||||
if response.IsModified(originalFeed.EtagHeader, originalFeed.LastModifiedHeader) {
|
||||
logger.Debug("[Handler:RefreshFeed] Feed #%d has been modified", feedID)
|
||||
|
||||
// Content-Length = -1 when no Content-Length header is sent
|
||||
if response.ContentLength == 0 {
|
||||
err := errors.NewLocalizedError(errEmptyFeed)
|
||||
originalFeed.ParsingErrorCount++
|
||||
originalFeed.ParsingErrorMsg = err.Error()
|
||||
h.store.UpdateFeed(originalFeed)
|
||||
return err
|
||||
}
|
||||
|
||||
body, err := response.NormalizeBodyEncoding()
|
||||
if err != nil {
|
||||
return errors.NewLocalizedError(errEncoding, err)
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
{{ if ne .feed.ParsingErrorCount 0 }}
|
||||
<div class="alert alert-error">
|
||||
<h3>{{ t "Last Parsing Error" }}</h3>
|
||||
{{ .feed.ParsingErrorMsg }}
|
||||
<p>{{ t .feed.ParsingErrorMsg }}</p>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
{{ if ne .feed.ParsingErrorCount 0 }}
|
||||
<div class="alert alert-error">
|
||||
<h3>{{ t "There is a problem with this feed" }}</h3>
|
||||
{{ .feed.ParsingErrorMsg }}
|
||||
<p>{{ t .feed.ParsingErrorMsg }}</p>
|
||||
</div>
|
||||
{{ else if not .entries }}
|
||||
<p class="alert">{{ t "There is no article for this feed." }}</p>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2018-01-04 18:06:27.666788074 -0800 PST m=+0.018144510
|
||||
// 2018-01-04 18:29:14.774068584 -0800 PST m=+0.005581816
|
||||
|
||||
package template
|
||||
|
||||
|
@ -390,7 +390,7 @@ var templateViewsMap = map[string]string{
|
|||
{{ if ne .feed.ParsingErrorCount 0 }}
|
||||
<div class="alert alert-error">
|
||||
<h3>{{ t "Last Parsing Error" }}</h3>
|
||||
{{ .feed.ParsingErrorMsg }}
|
||||
<p>{{ t .feed.ParsingErrorMsg }}</p>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
|
@ -621,7 +621,7 @@ var templateViewsMap = map[string]string{
|
|||
{{ if ne .feed.ParsingErrorCount 0 }}
|
||||
<div class="alert alert-error">
|
||||
<h3>{{ t "There is a problem with this feed" }}</h3>
|
||||
{{ .feed.ParsingErrorMsg }}
|
||||
<p>{{ t .feed.ParsingErrorMsg }}</p>
|
||||
</div>
|
||||
{{ else if not .entries }}
|
||||
<p class="alert">{{ t "There is no article for this feed." }}</p>
|
||||
|
@ -1342,10 +1342,10 @@ var templateViewsMapChecksums = map[string]string{
|
|||
"create_category": "2b82af5d2dcd67898dc5daa57a6461e6ff8121a6089b2a2a1be909f35e4a2275",
|
||||
"create_user": "45e226df757126d5fe7c464e295e9a34f07952cfdb71e31e49839850d35af139",
|
||||
"edit_category": "cee720faadcec58289b707ad30af623d2ee66c1ce23a732965463250d7ff41c5",
|
||||
"edit_feed": "15f19ab44057fca1630c6860d5951d6073f82f83ad682a176c475591c6f26377",
|
||||
"edit_feed": "30ff6ee5526b8beb9b457526b77ede55938f53eb279b1acc719ce896359e2ed8",
|
||||
"edit_user": "82d9749d76ddbd2352816d813c4b1f6d92f2222de678b4afe5821090246735c7",
|
||||
"entry": "6b4405e0c8e4a7d31874659f8835f4e43e01dc3c20686091517ac750196dd70f",
|
||||
"feed_entries": "ac93cb9a90f93ddd9dd8a67d7e160592ecb9f5e465ee9679bb14eecd8d4caf20",
|
||||
"feed_entries": "6b4a7d52b2590a7c54b58ed3180bd3bb5d869ceaecc80e3575339a9c351309c6",
|
||||
"feeds": "65b0a47c4438810b9d51c60f3f3b2519690e56ff74029e6296c68626b83a470b",
|
||||
"history": "abc7ea29f7d54f28f73fe14979bbd03dbc41fa6a7c86f95f56d6e94f7b09b9ba",
|
||||
"import": "73b5112e20bfd232bf73334544186ea419505936bc237d481517a8622901878f",
|
||||
|
|
Loading…
Reference in a new issue