aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/category.go2
-rw-r--r--api/entry.go8
-rw-r--r--api/feed.go4
-rw-r--r--api/icon.go2
-rw-r--r--api/subscription.go2
-rw-r--r--api/user.go8
-rw-r--r--fever/fever.go20
-rw-r--r--http/response/json/json.go6
-rw-r--r--http/response/response.go12
-rw-r--r--middleware/fever.go4
-rw-r--r--ui/entry_scraper.go2
-rw-r--r--ui/entry_toggle_bookmark.go2
-rw-r--r--ui/entry_update_status.go2
-rw-r--r--ui/static_manifest.go2
14 files changed, 41 insertions, 35 deletions
diff --git a/api/category.go b/api/category.go
index 30b12f4..b7b5c02 100644
--- a/api/category.go
+++ b/api/category.go
@@ -83,7 +83,7 @@ func (c *Controller) GetCategories(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, categories)
+ json.OK(w, r, categories)
}
// RemoveCategory is the API handler to remove a category.
diff --git a/api/entry.go b/api/entry.go
index a6785fb..b2a4d9d 100644
--- a/api/entry.go
+++ b/api/entry.go
@@ -48,7 +48,7 @@ func (c *Controller) GetFeedEntry(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, entry)
+ json.OK(w, r, entry)
}
// GetEntry is the API handler to get a single entry.
@@ -73,7 +73,7 @@ func (c *Controller) GetEntry(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, entry)
+ json.OK(w, r, entry)
}
// GetFeedEntries is the API handler to get all feed entries.
@@ -132,7 +132,7 @@ func (c *Controller) GetFeedEntries(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, &entriesResponse{Total: count, Entries: entries})
+ json.OK(w, r, &entriesResponse{Total: count, Entries: entries})
}
// GetEntries is the API handler to fetch entries.
@@ -184,7 +184,7 @@ func (c *Controller) GetEntries(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, &entriesResponse{Total: count, Entries: entries})
+ json.OK(w, r, &entriesResponse{Total: count, Entries: entries})
}
// SetEntryStatus is the API handler to change the status of entries.
diff --git a/api/feed.go b/api/feed.go
index b7c46ea..b6b6357 100644
--- a/api/feed.go
+++ b/api/feed.go
@@ -146,7 +146,7 @@ func (c *Controller) GetFeeds(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, feeds)
+ json.OK(w, r, feeds)
}
// GetFeed is the API handler to get a feed.
@@ -168,7 +168,7 @@ func (c *Controller) GetFeed(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, feed)
+ json.OK(w, r, feed)
}
// RemoveFeed is the API handler to remove a feed.
diff --git a/api/icon.go b/api/icon.go
index 0f5aa1b..052cdbc 100644
--- a/api/icon.go
+++ b/api/icon.go
@@ -37,7 +37,7 @@ func (c *Controller) FeedIcon(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, &feedIcon{
+ json.OK(w, r, &feedIcon{
ID: icon.ID,
MimeType: icon.MimeType,
Data: icon.DataURL(),
diff --git a/api/subscription.go b/api/subscription.go
index 19adc9e..a28c3b2 100644
--- a/api/subscription.go
+++ b/api/subscription.go
@@ -36,5 +36,5 @@ func (c *Controller) GetSubscriptions(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, subscriptions)
+ json.OK(w, r, subscriptions)
}
diff --git a/api/user.go b/api/user.go
index 4e5fa82..b880ba3 100644
--- a/api/user.go
+++ b/api/user.go
@@ -22,7 +22,7 @@ func (c *Controller) CurrentUser(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, user)
+ json.OK(w, r, user)
}
// CreateUser is the API handler to create a new user.
@@ -119,7 +119,7 @@ func (c *Controller) Users(w http.ResponseWriter, r *http.Request) {
}
users.UseTimezone(ctx.UserTimezone())
- json.OK(w, users)
+ json.OK(w, r, users)
}
// UserByID is the API handler to fetch the given user by the ID.
@@ -148,7 +148,7 @@ func (c *Controller) UserByID(w http.ResponseWriter, r *http.Request) {
}
user.UseTimezone(ctx.UserTimezone())
- json.OK(w, user)
+ json.OK(w, r, user)
}
// UserByUsername is the API handler to fetch the given user by the username.
@@ -171,7 +171,7 @@ func (c *Controller) UserByUsername(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, user)
+ json.OK(w, r, user)
}
// RemoveUser is the API handler to remove an existing user.
diff --git a/fever/fever.go b/fever/fever.go
index 9fb6bdb..44e155a 100644
--- a/fever/fever.go
+++ b/fever/fever.go
@@ -155,7 +155,7 @@ func (c *Controller) Handler(w http.ResponseWriter, r *http.Request) {
case r.FormValue("mark") == "group":
c.handleWriteGroups(w, r)
default:
- json.OK(w, newBaseResponse())
+ json.OK(w, r, newBaseResponse())
}
}
@@ -203,7 +203,7 @@ func (c *Controller) handleGroups(w http.ResponseWriter, r *http.Request) {
result.FeedsGroups = c.buildFeedGroups(feeds)
result.SetCommonValues()
- json.OK(w, result)
+ json.OK(w, r, result)
}
/*
@@ -262,7 +262,7 @@ func (c *Controller) handleFeeds(w http.ResponseWriter, r *http.Request) {
result.FeedsGroups = c.buildFeedGroups(feeds)
result.SetCommonValues()
- json.OK(w, result)
+ json.OK(w, r, result)
}
/*
@@ -304,7 +304,7 @@ func (c *Controller) handleFavicons(w http.ResponseWriter, r *http.Request) {
}
result.SetCommonValues()
- json.OK(w, result)
+ json.OK(w, r, result)
}
/*
@@ -414,7 +414,7 @@ func (c *Controller) handleItems(w http.ResponseWriter, r *http.Request) {
}
result.SetCommonValues()
- json.OK(w, result)
+ json.OK(w, r, result)
}
/*
@@ -445,7 +445,7 @@ func (c *Controller) handleUnreadItems(w http.ResponseWriter, r *http.Request) {
var result unreadResponse
result.ItemIDs = strings.Join(itemIDs, ",")
result.SetCommonValues()
- json.OK(w, result)
+ json.OK(w, r, result)
}
/*
@@ -477,7 +477,7 @@ func (c *Controller) handleSavedItems(w http.ResponseWriter, r *http.Request) {
result := &savedResponse{ItemIDs: strings.Join(itemsIDs, ",")}
result.SetCommonValues()
- json.OK(w, result)
+ json.OK(w, r, result)
}
/*
@@ -534,7 +534,7 @@ func (c *Controller) handleWriteItems(w http.ResponseWriter, r *http.Request) {
}()
}
- json.OK(w, newBaseResponse())
+ json.OK(w, r, newBaseResponse())
}
/*
@@ -575,7 +575,7 @@ func (c *Controller) handleWriteFeeds(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, newBaseResponse())
+ json.OK(w, r, newBaseResponse())
}
/*
@@ -616,7 +616,7 @@ func (c *Controller) handleWriteGroups(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, newBaseResponse())
+ json.OK(w, r, newBaseResponse())
}
/*
diff --git a/http/response/json/json.go b/http/response/json/json.go
index ff0f06b..6f3eb15 100644
--- a/http/response/json/json.go
+++ b/http/response/json/json.go
@@ -9,14 +9,14 @@ import (
"errors"
"net/http"
+ "github.com/miniflux/miniflux/http/response"
"github.com/miniflux/miniflux/logger"
)
// OK sends a JSON response with the status code 200.
-func OK(w http.ResponseWriter, v interface{}) {
+func OK(w http.ResponseWriter, r *http.Request, v interface{}) {
commonHeaders(w)
- w.WriteHeader(http.StatusOK)
- w.Write(toJSON(v))
+ response.Compress(w, r, toJSON(v))
}
// Created sends a JSON response with the status code 201.
diff --git a/http/response/response.go b/http/response/response.go
index c5ae3fa..f792625 100644
--- a/http/response/response.go
+++ b/http/response/response.go
@@ -23,7 +23,7 @@ func NotModified(w http.ResponseWriter) {
}
// Cache returns a response with caching headers.
-func Cache(w http.ResponseWriter, r *http.Request, mimeType, etag string, content []byte, duration time.Duration) {
+func Cache(w http.ResponseWriter, r *http.Request, mimeType, etag string, data []byte, duration time.Duration) {
w.Header().Set("Content-Type", mimeType)
w.Header().Set("ETag", etag)
w.Header().Set("Cache-Control", "public")
@@ -31,8 +31,14 @@ func Cache(w http.ResponseWriter, r *http.Request, mimeType, etag string, conten
if etag == r.Header.Get("If-None-Match") {
w.WriteHeader(http.StatusNotModified)
- } else {
- w.Write(content)
+ return
+ }
+
+ switch mimeType {
+ case "text/javascript; charset=utf-8", "text/css; charset=utf-8":
+ Compress(w, r, data)
+ default:
+ w.Write(data)
}
}
diff --git a/middleware/fever.go b/middleware/fever.go
index 78217e4..6211fb7 100644
--- a/middleware/fever.go
+++ b/middleware/fever.go
@@ -20,13 +20,13 @@ func (m *Middleware) FeverAuth(next http.Handler) http.Handler {
user, err := m.store.UserByFeverToken(apiKey)
if err != nil {
logger.Error("[Middleware:Fever] %v", err)
- json.OK(w, map[string]int{"api_version": 3, "auth": 0})
+ json.OK(w, r, map[string]int{"api_version": 3, "auth": 0})
return
}
if user == nil {
logger.Info("[Middleware:Fever] Fever authentication failure")
- json.OK(w, map[string]int{"api_version": 3, "auth": 0})
+ json.OK(w, r, map[string]int{"api_version": 3, "auth": 0})
return
}
diff --git a/ui/entry_scraper.go b/ui/entry_scraper.go
index 75e4040..aea9b20 100644
--- a/ui/entry_scraper.go
+++ b/ui/entry_scraper.go
@@ -49,5 +49,5 @@ func (c *Controller) FetchContent(w http.ResponseWriter, r *http.Request) {
entry.Content = sanitizer.Sanitize(entry.URL, content)
c.store.UpdateEntryContent(entry)
- json.Created(w, map[string]string{"content": entry.Content})
+ json.OK(w, r, map[string]string{"content": entry.Content})
}
diff --git a/ui/entry_toggle_bookmark.go b/ui/entry_toggle_bookmark.go
index 423fde8..9d94cd1 100644
--- a/ui/entry_toggle_bookmark.go
+++ b/ui/entry_toggle_bookmark.go
@@ -28,5 +28,5 @@ func (c *Controller) ToggleBookmark(w http.ResponseWriter, r *http.Request) {
return
}
- json.OK(w, "OK")
+ json.OK(w, r, "OK")
}
diff --git a/ui/entry_update_status.go b/ui/entry_update_status.go
index 3174d85..bafa0a0 100644
--- a/ui/entry_update_status.go
+++ b/ui/entry_update_status.go
@@ -35,5 +35,5 @@ func (c *Controller) UpdateEntriesStatus(w http.ResponseWriter, r *http.Request)
return
}
- json.OK(w, "OK")
+ json.OK(w, r, "OK")
}
diff --git a/ui/static_manifest.go b/ui/static_manifest.go
index 27abaec..96814fe 100644
--- a/ui/static_manifest.go
+++ b/ui/static_manifest.go
@@ -50,5 +50,5 @@ func (c *Controller) WebManifest(w http.ResponseWriter, r *http.Request) {
},
}
- json.OK(w, manifest)
+ json.OK(w, r, manifest)
}