From 1f58b37a5e86603b16e137031c36f37580e9d410 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 7 Oct 2018 18:42:43 -0700 Subject: Refactor HTTP response builder --- ui/about.go | 2 +- ui/bookmark_entries.go | 8 ++++---- ui/category_create.go | 2 +- ui/category_edit.go | 8 ++++---- ui/category_entries.go | 12 ++++++------ ui/category_list.go | 6 +++--- ui/category_remove.go | 11 +++++------ ui/category_save.go | 9 ++++----- ui/category_update.go | 11 +++++------ ui/entry_bookmark.go | 14 ++++++-------- ui/entry_category.go | 14 ++++++-------- ui/entry_feed.go | 14 ++++++-------- ui/entry_read.go | 10 +++++----- ui/entry_save.go | 9 ++++----- ui/entry_scraper.go | 9 ++++----- ui/entry_search.go | 12 ++++++------ ui/entry_toggle_bookmark.go | 4 +--- ui/entry_unread.go | 17 +++++++---------- ui/entry_update_status.go | 9 +++------ ui/feed_edit.go | 10 +++++----- ui/feed_entries.go | 12 ++++++------ ui/feed_icon.go | 13 +++++++++---- ui/feed_list.go | 4 ++-- ui/feed_refresh.go | 9 ++++----- ui/feed_remove.go | 5 ++--- ui/feed_update.go | 13 ++++++------- ui/history_entries.go | 8 ++++---- ui/history_flush.go | 5 ++--- ui/integration_pocket.go | 21 ++++++++++----------- ui/integration_show.go | 6 +++--- ui/integration_update.go | 15 +++++++-------- ui/login_check.go | 7 +++---- ui/login_show.go | 7 +++---- ui/logout.go | 7 +++---- ui/oauth2.go | 2 +- ui/oauth2_callback.go | 31 +++++++++++++++---------------- ui/oauth2_redirect.go | 10 +++++----- ui/oauth2_unlink.go | 15 +++++++-------- ui/opml_export.go | 4 ++-- ui/opml_import.go | 4 ++-- ui/opml_upload.go | 9 ++++----- ui/proxy.go | 23 +++++++++++++---------- ui/search_entries.go | 8 ++++---- ui/session_list.go | 8 ++++---- ui/session_remove.go | 4 ++-- ui/settings_show.go | 6 +++--- ui/settings_update.go | 9 ++++----- ui/static_app_icon.go | 26 ++++++++++++++------------ ui/static_favicon.go | 25 +++++++++++++++++-------- ui/static_javascript.go | 14 ++++++++------ ui/static_stylesheet.go | 16 +++++++++------- ui/subscription_add.go | 4 ++-- ui/subscription_bookmarklet.go | 4 ++-- ui/subscription_choose.go | 9 ++++----- ui/subscription_submit.go | 7 +++---- ui/unread_entries.go | 8 ++++---- ui/unread_mark_all_read.go | 4 ++-- ui/user_create.go | 4 ++-- ui/user_edit.go | 10 +++++----- ui/user_list.go | 8 ++++---- ui/user_remove.go | 13 ++++++------- ui/user_save.go | 7 +++---- ui/user_update.go | 13 ++++++------- 63 files changed, 307 insertions(+), 321 deletions(-) (limited to 'ui') diff --git a/ui/about.go b/ui/about.go index e11ab52..abc39a0 100644 --- a/ui/about.go +++ b/ui/about.go @@ -18,7 +18,7 @@ import ( func (c *Controller) About(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/bookmark_entries.go b/ui/bookmark_entries.go index 08385f6..5e6bb45 100644 --- a/ui/bookmark_entries.go +++ b/ui/bookmark_entries.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -19,7 +19,7 @@ import ( func (c *Controller) ShowStarredPage(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -34,13 +34,13 @@ func (c *Controller) ShowStarredPage(w http.ResponseWriter, r *http.Request) { entries, err := builder.GetEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } count, err := builder.CountEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/category_create.go b/ui/category_create.go index 20d280a..bd5039f 100644 --- a/ui/category_create.go +++ b/ui/category_create.go @@ -17,7 +17,7 @@ import ( func (c *Controller) CreateCategory(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/category_edit.go b/ui/category_edit.go index b99d2a0..e0375be 100644 --- a/ui/category_edit.go +++ b/ui/category_edit.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -21,19 +21,19 @@ func (c *Controller) EditCategory(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } categoryID := request.RouteInt64Param(r, "categoryID") category, err := c.store.Category(request.UserID(r), categoryID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if category == nil { - html.NotFound(w) + html.NotFound(w, r) return } diff --git a/ui/category_entries.go b/ui/category_entries.go index caa98cd..fe5f638 100644 --- a/ui/category_entries.go +++ b/ui/category_entries.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -19,19 +19,19 @@ import ( func (c *Controller) CategoryEntries(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } categoryID := request.RouteInt64Param(r, "categoryID") category, err := c.store.Category(request.UserID(r), categoryID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if category == nil { - html.NotFound(w) + html.NotFound(w, r) return } @@ -46,13 +46,13 @@ func (c *Controller) CategoryEntries(w http.ResponseWriter, r *http.Request) { entries, err := builder.GetEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } count, err := builder.CountEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/category_list.go b/ui/category_list.go index 3dc17ca..f4a3651 100644 --- a/ui/category_list.go +++ b/ui/category_list.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -17,13 +17,13 @@ import ( func (c *Controller) CategoryList(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } categories, err := c.store.CategoriesWithFeedCount(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/category_remove.go b/ui/category_remove.go index b424af5..f8a38dc 100644 --- a/ui/category_remove.go +++ b/ui/category_remove.go @@ -8,7 +8,6 @@ import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" ) @@ -17,26 +16,26 @@ import ( func (c *Controller) RemoveCategory(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } categoryID := request.RouteInt64Param(r, "categoryID") category, err := c.store.Category(request.UserID(r), categoryID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if category == nil { - html.NotFound(w) + html.NotFound(w, r) return } if err := c.store.RemoveCategory(user.ID, category.ID); err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } - response.Redirect(w, r, route.Path(c.router, "categories")) + html.Redirect(w, r, route.Path(c.router, "categories")) } diff --git a/ui/category_save.go b/ui/category_save.go index ec85cd3..d115d0a 100644 --- a/ui/category_save.go +++ b/ui/category_save.go @@ -2,12 +2,11 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/http/request" @@ -22,7 +21,7 @@ import ( func (c *Controller) SaveCategory(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -44,7 +43,7 @@ func (c *Controller) SaveCategory(w http.ResponseWriter, r *http.Request) { duplicateCategory, err := c.store.CategoryByTitle(user.ID, categoryForm.Title) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -66,5 +65,5 @@ func (c *Controller) SaveCategory(w http.ResponseWriter, r *http.Request) { return } - response.Redirect(w, r, route.Path(c.router, "categories")) + html.Redirect(w, r, route.Path(c.router, "categories")) } diff --git a/ui/category_update.go b/ui/category_update.go index 90672c0..6ef5648 100644 --- a/ui/category_update.go +++ b/ui/category_update.go @@ -2,13 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/logger" @@ -21,19 +20,19 @@ import ( func (c *Controller) UpdateCategory(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } categoryID := request.RouteInt64Param(r, "categoryID") category, err := c.store.Category(request.UserID(r), categoryID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if category == nil { - html.NotFound(w) + html.NotFound(w, r) return } @@ -68,5 +67,5 @@ func (c *Controller) UpdateCategory(w http.ResponseWriter, r *http.Request) { return } - response.Redirect(w, r, route.Path(c.router, "categories")) + html.Redirect(w, r, route.Path(c.router, "categories")) } diff --git a/ui/entry_bookmark.go b/ui/entry_bookmark.go index 7c42a5c..895c2bc 100644 --- a/ui/entry_bookmark.go +++ b/ui/entry_bookmark.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -10,7 +10,6 @@ import ( "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" - "miniflux.app/logger" "miniflux.app/model" "miniflux.app/storage" "miniflux.app/ui/session" @@ -21,7 +20,7 @@ import ( func (c *Controller) ShowStarredEntry(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -32,20 +31,19 @@ func (c *Controller) ShowStarredEntry(w http.ResponseWriter, r *http.Request) { entry, err := builder.GetEntry() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if entry == nil { - html.NotFound(w) + html.NotFound(w, r) return } if entry.Status == model.EntryStatusUnread { err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead) if err != nil { - logger.Error("[Controller:ShowReadEntry] %v", err) - html.ServerError(w, nil) + html.ServerError(w, r, err) return } @@ -56,7 +54,7 @@ func (c *Controller) ShowStarredEntry(w http.ResponseWriter, r *http.Request) { entryPaginationBuilder.WithStarred() prevEntry, nextEntry, err := entryPaginationBuilder.Entries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/entry_category.go b/ui/entry_category.go index 283f015..d11248b 100644 --- a/ui/entry_category.go +++ b/ui/entry_category.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -10,7 +10,6 @@ import ( "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" - "miniflux.app/logger" "miniflux.app/model" "miniflux.app/storage" "miniflux.app/ui/session" @@ -21,7 +20,7 @@ import ( func (c *Controller) ShowCategoryEntry(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -35,20 +34,19 @@ func (c *Controller) ShowCategoryEntry(w http.ResponseWriter, r *http.Request) { entry, err := builder.GetEntry() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if entry == nil { - html.NotFound(w) + html.NotFound(w, r) return } if entry.Status == model.EntryStatusUnread { err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead) if err != nil { - logger.Error("[Controller:ShowCategoryEntry] %v", err) - html.ServerError(w, nil) + html.ServerError(w, r, err) return } @@ -59,7 +57,7 @@ func (c *Controller) ShowCategoryEntry(w http.ResponseWriter, r *http.Request) { entryPaginationBuilder.WithCategoryID(categoryID) prevEntry, nextEntry, err := entryPaginationBuilder.Entries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/entry_feed.go b/ui/entry_feed.go index 86dd2c9..9c28c67 100644 --- a/ui/entry_feed.go +++ b/ui/entry_feed.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -10,7 +10,6 @@ import ( "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" - "miniflux.app/logger" "miniflux.app/model" "miniflux.app/storage" "miniflux.app/ui/session" @@ -21,7 +20,7 @@ import ( func (c *Controller) ShowFeedEntry(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -35,20 +34,19 @@ func (c *Controller) ShowFeedEntry(w http.ResponseWriter, r *http.Request) { entry, err := builder.GetEntry() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if entry == nil { - html.NotFound(w) + html.NotFound(w, r) return } if entry.Status == model.EntryStatusUnread { err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead) if err != nil { - logger.Error("[Controller:ShowFeedEntry] %v", err) - html.ServerError(w, nil) + html.ServerError(w, r, err) return } @@ -59,7 +57,7 @@ func (c *Controller) ShowFeedEntry(w http.ResponseWriter, r *http.Request) { entryPaginationBuilder.WithFeedID(feedID) prevEntry, nextEntry, err := entryPaginationBuilder.Entries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/entry_read.go b/ui/entry_read.go index eeaca8e..208ae3b 100644 --- a/ui/entry_read.go +++ b/ui/entry_read.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -20,7 +20,7 @@ import ( func (c *Controller) ShowReadEntry(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -31,12 +31,12 @@ func (c *Controller) ShowReadEntry(w http.ResponseWriter, r *http.Request) { entry, err := builder.GetEntry() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if entry == nil { - html.NotFound(w) + html.NotFound(w, r) return } @@ -44,7 +44,7 @@ func (c *Controller) ShowReadEntry(w http.ResponseWriter, r *http.Request) { entryPaginationBuilder.WithStatus(model.EntryStatusRead) prevEntry, nextEntry, err := entryPaginationBuilder.Entries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/entry_save.go b/ui/entry_save.go index 1f846ba..93910c0 100644 --- a/ui/entry_save.go +++ b/ui/entry_save.go @@ -5,7 +5,6 @@ package ui // import "miniflux.app/ui" import ( - "errors" "net/http" "miniflux.app/http/request" @@ -23,18 +22,18 @@ func (c *Controller) SaveEntry(w http.ResponseWriter, r *http.Request) { entry, err := builder.GetEntry() if err != nil { - json.ServerError(w, err) + json.ServerError(w, r, err) return } if entry == nil { - json.NotFound(w, errors.New("Entry not found")) + json.NotFound(w, r) return } settings, err := c.store.Integration(request.UserID(r)) if err != nil { - json.ServerError(w, err) + json.ServerError(w, r, err) return } @@ -42,5 +41,5 @@ func (c *Controller) SaveEntry(w http.ResponseWriter, r *http.Request) { integration.SendEntry(c.cfg, entry, settings) }() - json.Created(w, map[string]string{"message": "saved"}) + json.Created(w, r, map[string]string{"message": "saved"}) } diff --git a/ui/entry_scraper.go b/ui/entry_scraper.go index 4c2d58c..c35d949 100644 --- a/ui/entry_scraper.go +++ b/ui/entry_scraper.go @@ -2,10 +2,9 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( - "errors" "net/http" "miniflux.app/http/request" @@ -24,18 +23,18 @@ func (c *Controller) FetchContent(w http.ResponseWriter, r *http.Request) { entry, err := builder.GetEntry() if err != nil { - json.ServerError(w, err) + json.ServerError(w, r, err) return } if entry == nil { - json.NotFound(w, errors.New("Entry not found")) + json.NotFound(w, r) return } content, err := scraper.Fetch(entry.URL, entry.Feed.ScraperRules, entry.Feed.UserAgent) if err != nil { - json.ServerError(w, err) + json.ServerError(w, r, err) return } diff --git a/ui/entry_search.go b/ui/entry_search.go index 8acf103..d083b35 100644 --- a/ui/entry_search.go +++ b/ui/entry_search.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -21,7 +21,7 @@ import ( func (c *Controller) ShowSearchEntry(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -34,12 +34,12 @@ func (c *Controller) ShowSearchEntry(w http.ResponseWriter, r *http.Request) { entry, err := builder.GetEntry() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if entry == nil { - html.NotFound(w) + html.NotFound(w, r) return } @@ -47,7 +47,7 @@ func (c *Controller) ShowSearchEntry(w http.ResponseWriter, r *http.Request) { err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead) if err != nil { logger.Error("[Controller:ShowSearchEntry] %v", err) - html.ServerError(w, nil) + html.ServerError(w, r, err) return } @@ -58,7 +58,7 @@ func (c *Controller) ShowSearchEntry(w http.ResponseWriter, r *http.Request) { entryPaginationBuilder.WithSearchQuery(searchQuery) prevEntry, nextEntry, err := entryPaginationBuilder.Entries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/entry_toggle_bookmark.go b/ui/entry_toggle_bookmark.go index 14a2c75..9f7a3e7 100644 --- a/ui/entry_toggle_bookmark.go +++ b/ui/entry_toggle_bookmark.go @@ -9,15 +9,13 @@ import ( "miniflux.app/http/request" "miniflux.app/http/response/json" - "miniflux.app/logger" ) // ToggleBookmark handles Ajax request to toggle bookmark value. func (c *Controller) ToggleBookmark(w http.ResponseWriter, r *http.Request) { entryID := request.RouteInt64Param(r, "entryID") if err := c.store.ToggleBookmark(request.UserID(r), entryID); err != nil { - logger.Error("[Controller:ToggleBookmark] %v", err) - json.ServerError(w, nil) + json.ServerError(w, r, err) return } diff --git a/ui/entry_unread.go b/ui/entry_unread.go index 4ef5731..37e9592 100644 --- a/ui/entry_unread.go +++ b/ui/entry_unread.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -10,7 +10,6 @@ import ( "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" - "miniflux.app/logger" "miniflux.app/model" "miniflux.app/storage" "miniflux.app/ui/session" @@ -21,7 +20,7 @@ import ( func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -32,12 +31,12 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) { entry, err := builder.GetEntry() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if entry == nil { - html.NotFound(w) + html.NotFound(w, r) return } @@ -45,8 +44,7 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) { if entry.Status == model.EntryStatusRead { err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusUnread) if err != nil { - logger.Error("[Controller:ShowUnreadEntry] %v", err) - html.ServerError(w, nil) + html.ServerError(w, r, err) return } } @@ -55,7 +53,7 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) { entryPaginationBuilder.WithStatus(model.EntryStatusUnread) prevEntry, nextEntry, err := entryPaginationBuilder.Entries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -72,8 +70,7 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) { // Always mark the entry as read after fetching the pagination. err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead) if err != nil { - logger.Error("[Controller:ShowUnreadEntry] %v", err) - html.ServerError(w, nil) + html.ServerError(w, r, err) return } entry.Status = model.EntryStatusRead diff --git a/ui/entry_update_status.go b/ui/entry_update_status.go index 8e9de4d..6c5cb12 100644 --- a/ui/entry_update_status.go +++ b/ui/entry_update_status.go @@ -10,27 +10,24 @@ import ( "miniflux.app/http/request" "miniflux.app/http/response/json" - "miniflux.app/logger" ) // UpdateEntriesStatus updates the status for a list of entries. func (c *Controller) UpdateEntriesStatus(w http.ResponseWriter, r *http.Request) { entryIDs, status, err := decodeEntryStatusPayload(r.Body) if err != nil { - logger.Error("[Controller:UpdateEntryStatus] %v", err) - json.BadRequest(w, nil) + json.BadRequest(w, r, err) return } if len(entryIDs) == 0 { - json.BadRequest(w, errors.New("The list of entryID is empty")) + json.BadRequest(w, r, errors.New("The list of entry IDs is empty")) return } err = c.store.SetEntriesStatus(request.UserID(r), entryIDs, status) if err != nil { - logger.Error("[Controller:UpdateEntryStatus] %v", err) - json.ServerError(w, nil) + json.ServerError(w, r, err) return } diff --git a/ui/feed_edit.go b/ui/feed_edit.go index 8b1b3cb..330817b 100644 --- a/ui/feed_edit.go +++ b/ui/feed_edit.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -19,25 +19,25 @@ import ( func (c *Controller) EditFeed(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } feedID := request.RouteInt64Param(r, "feedID") feed, err := c.store.FeedByID(user.ID, feedID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if feed == nil { - html.NotFound(w) + html.NotFound(w, r) return } categories, err := c.store.Categories(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/feed_entries.go b/ui/feed_entries.go index 06a298b..685b5c1 100644 --- a/ui/feed_entries.go +++ b/ui/feed_entries.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -19,19 +19,19 @@ import ( func (c *Controller) ShowFeedEntries(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } feedID := request.RouteInt64Param(r, "feedID") feed, err := c.store.FeedByID(user.ID, feedID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if feed == nil { - html.NotFound(w) + html.NotFound(w, r) return } @@ -46,13 +46,13 @@ func (c *Controller) ShowFeedEntries(w http.ResponseWriter, r *http.Request) { entries, err := builder.GetEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } count, err := builder.CountEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/feed_icon.go b/ui/feed_icon.go index 0aa7089..63aa050 100644 --- a/ui/feed_icon.go +++ b/ui/feed_icon.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -18,14 +18,19 @@ func (c *Controller) ShowIcon(w http.ResponseWriter, r *http.Request) { iconID := request.RouteInt64Param(r, "iconID") icon, err := c.store.IconByID(iconID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if icon == nil { - html.NotFound(w) + html.NotFound(w, r) return } - response.Cache(w, r, icon.MimeType, icon.Hash, icon.Content, 72*time.Hour) + response.New(w, r).WithCaching(icon.Hash, 72*time.Hour, func(b *response.Builder) { + b.WithHeader("Content-Type", icon.MimeType) + b.WithBody(icon.Content) + b.WithoutCompression() + b.Write() + }) } diff --git a/ui/feed_list.go b/ui/feed_list.go index 9fe4aac..ac5a97c 100644 --- a/ui/feed_list.go +++ b/ui/feed_list.go @@ -17,13 +17,13 @@ import ( func (c *Controller) ShowFeedsPage(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } feeds, err := c.store.Feeds(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/feed_refresh.go b/ui/feed_refresh.go index df93c6e..0da4eb8 100644 --- a/ui/feed_refresh.go +++ b/ui/feed_refresh.go @@ -2,13 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/logger" @@ -21,7 +20,7 @@ func (c *Controller) RefreshFeed(w http.ResponseWriter, r *http.Request) { logger.Error("[Controller:RefreshFeed] %v", err) } - response.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feedID)) + html.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feedID)) } // RefreshAllFeeds refresh all feeds in the background for the current user. @@ -29,7 +28,7 @@ func (c *Controller) RefreshAllFeeds(w http.ResponseWriter, r *http.Request) { userID := request.UserID(r) jobs, err := c.store.NewUserBatch(userID, c.store.CountFeeds(userID)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -37,5 +36,5 @@ func (c *Controller) RefreshAllFeeds(w http.ResponseWriter, r *http.Request) { c.pool.Push(jobs) }() - response.Redirect(w, r, route.Path(c.router, "feeds")) + html.Redirect(w, r, route.Path(c.router, "feeds")) } diff --git a/ui/feed_remove.go b/ui/feed_remove.go index d1ab01a..41fc5b0 100644 --- a/ui/feed_remove.go +++ b/ui/feed_remove.go @@ -8,7 +8,6 @@ import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" ) @@ -17,9 +16,9 @@ import ( func (c *Controller) RemoveFeed(w http.ResponseWriter, r *http.Request) { feedID := request.RouteInt64Param(r, "feedID") if err := c.store.RemoveFeed(request.UserID(r), feedID); err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } - response.Redirect(w, r, route.Path(c.router, "feeds")) + html.Redirect(w, r, route.Path(c.router, "feeds")) } diff --git a/ui/feed_update.go b/ui/feed_update.go index 6cc4776..66b6d40 100644 --- a/ui/feed_update.go +++ b/ui/feed_update.go @@ -2,14 +2,13 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/client" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/logger" @@ -22,25 +21,25 @@ import ( func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } feedID := request.RouteInt64Param(r, "feedID") feed, err := c.store.FeedByID(user.ID, feedID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if feed == nil { - html.NotFound(w) + html.NotFound(w, r) return } categories, err := c.store.Categories(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -71,5 +70,5 @@ func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) { return } - response.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID)) + html.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID)) } diff --git a/ui/history_entries.go b/ui/history_entries.go index 25310a9..8449240 100644 --- a/ui/history_entries.go +++ b/ui/history_entries.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -19,7 +19,7 @@ import ( func (c *Controller) ShowHistoryPage(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -33,13 +33,13 @@ func (c *Controller) ShowHistoryPage(w http.ResponseWriter, r *http.Request) { entries, err := builder.GetEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } count, err := builder.CountEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/history_flush.go b/ui/history_flush.go index 5bb8910..6c6907b 100644 --- a/ui/history_flush.go +++ b/ui/history_flush.go @@ -8,7 +8,6 @@ import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" ) @@ -17,9 +16,9 @@ import ( func (c *Controller) FlushHistory(w http.ResponseWriter, r *http.Request) { err := c.store.FlushHistory(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } - response.Redirect(w, r, route.Path(c.router, "history")) + html.Redirect(w, r, route.Path(c.router, "history")) } diff --git a/ui/integration_pocket.go b/ui/integration_pocket.go index 407731e..47a975c 100644 --- a/ui/integration_pocket.go +++ b/ui/integration_pocket.go @@ -7,9 +7,8 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/response" - "miniflux.app/http/request" "miniflux.app/http/response/html" + "miniflux.app/http/request" "miniflux.app/http/route" "miniflux.app/integration/pocket" "miniflux.app/locale" @@ -22,13 +21,13 @@ func (c *Controller) PocketAuthorize(w http.ResponseWriter, r *http.Request) { printer := locale.NewPrinter(request.UserLanguage(r)) user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } integration, err := c.store.Integration(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -39,12 +38,12 @@ func (c *Controller) PocketAuthorize(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Error("[Pocket:Authorize] %v", err) sess.NewFlashErrorMessage(printer.Printf("error.pocket_request_token")) - response.Redirect(w, r, route.Path(c.router, "integrations")) + html.Redirect(w, r, route.Path(c.router, "integrations")) return } sess.SetPocketRequestToken(requestToken) - response.Redirect(w, r, connector.AuthorizationURL(requestToken, redirectURL)) + html.Redirect(w, r, connector.AuthorizationURL(requestToken, redirectURL)) } // PocketCallback saves the personal access token after the authorization step. @@ -54,13 +53,13 @@ func (c *Controller) PocketCallback(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } integration, err := c.store.Integration(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -69,7 +68,7 @@ func (c *Controller) PocketCallback(w http.ResponseWriter, r *http.Request) { if err != nil { logger.Error("[Pocket:Callback] %v", err) sess.NewFlashErrorMessage(printer.Printf("error.pocket_access_token")) - response.Redirect(w, r, route.Path(c.router, "integrations")) + html.Redirect(w, r, route.Path(c.router, "integrations")) return } @@ -78,10 +77,10 @@ func (c *Controller) PocketCallback(w http.ResponseWriter, r *http.Request) { err = c.store.UpdateIntegration(integration) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } sess.NewFlashMessage(printer.Printf("alert.pocket_linked")) - response.Redirect(w, r, route.Path(c.router, "integrations")) + html.Redirect(w, r, route.Path(c.router, "integrations")) } diff --git a/ui/integration_show.go b/ui/integration_show.go index 1c8adce..3cea830 100644 --- a/ui/integration_show.go +++ b/ui/integration_show.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -18,13 +18,13 @@ import ( func (c *Controller) ShowIntegrations(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } integration, err := c.store.Integration(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/integration_update.go b/ui/integration_update.go index f470e4b..5661daf 100644 --- a/ui/integration_update.go +++ b/ui/integration_update.go @@ -2,16 +2,15 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "crypto/md5" "fmt" "net/http" - "miniflux.app/http/response" - "miniflux.app/http/request" "miniflux.app/http/response/html" + "miniflux.app/http/request" "miniflux.app/http/route" "miniflux.app/locale" "miniflux.app/ui/form" @@ -24,13 +23,13 @@ func (c *Controller) UpdateIntegration(w http.ResponseWriter, r *http.Request) { sess := session.New(c.store, request.SessionID(r)) user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } integration, err := c.store.Integration(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -39,7 +38,7 @@ func (c *Controller) UpdateIntegration(w http.ResponseWriter, r *http.Request) { if integration.FeverUsername != "" && c.store.HasDuplicateFeverUsername(user.ID, integration.FeverUsername) { sess.NewFlashErrorMessage(printer.Printf("error.duplicate_fever_username")) - response.Redirect(w, r, route.Path(c.router, "integrations")) + html.Redirect(w, r, route.Path(c.router, "integrations")) return } @@ -51,10 +50,10 @@ func (c *Controller) UpdateIntegration(w http.ResponseWriter, r *http.Request) { err = c.store.UpdateIntegration(integration) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } sess.NewFlashMessage(printer.Printf("alert.prefs_saved")) - response.Redirect(w, r, route.Path(c.router, "integrations")) + html.Redirect(w, r, route.Path(c.router, "integrations")) } diff --git a/ui/login_check.go b/ui/login_check.go index 98d2c4e..73a1736 100644 --- a/ui/login_check.go +++ b/ui/login_check.go @@ -5,7 +5,6 @@ import ( "miniflux.app/http/cookie" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/logger" @@ -38,7 +37,7 @@ func (c *Controller) CheckLogin(w http.ResponseWriter, r *http.Request) { sessionToken, userID, err := c.store.CreateUserSession(authForm.Username, r.UserAgent(), clientIP) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -47,7 +46,7 @@ func (c *Controller) CheckLogin(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(userID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -61,5 +60,5 @@ func (c *Controller) CheckLogin(w http.ResponseWriter, r *http.Request) { c.cfg.BasePath(), )) - response.Redirect(w, r, route.Path(c.router, "unread")) + html.Redirect(w, r, route.Path(c.router, "unread")) } diff --git a/ui/login_show.go b/ui/login_show.go index 82c19ec..890f9db 100644 --- a/ui/login_show.go +++ b/ui/login_show.go @@ -2,14 +2,13 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/response" - "miniflux.app/http/request" "miniflux.app/http/response/html" + "miniflux.app/http/request" "miniflux.app/http/route" "miniflux.app/ui/session" "miniflux.app/ui/view" @@ -18,7 +17,7 @@ import ( // ShowLoginPage shows the login form. func (c *Controller) ShowLoginPage(w http.ResponseWriter, r *http.Request) { if request.IsAuthenticated(r) { - response.Redirect(w, r, route.Path(c.router, "unread")) + html.Redirect(w, r, route.Path(c.router, "unread")) return } diff --git a/ui/logout.go b/ui/logout.go index 0c8e9e7..59f8af2 100644 --- a/ui/logout.go +++ b/ui/logout.go @@ -2,14 +2,13 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/cookie" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/logger" @@ -21,7 +20,7 @@ func (c *Controller) Logout(w http.ResponseWriter, r *http.Request) { sess := session.New(c.store, request.SessionID(r)) user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -38,5 +37,5 @@ func (c *Controller) Logout(w http.ResponseWriter, r *http.Request) { c.cfg.BasePath(), )) - response.Redirect(w, r, route.Path(c.router, "login")) + html.Redirect(w, r, route.Path(c.router, "login")) } diff --git a/ui/oauth2.go b/ui/oauth2.go index 3f964a6..c5d594f 100644 --- a/ui/oauth2.go +++ b/ui/oauth2.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "miniflux.app/config" diff --git a/ui/oauth2_callback.go b/ui/oauth2_callback.go index 1902d6e..feaccc4 100644 --- a/ui/oauth2_callback.go +++ b/ui/oauth2_callback.go @@ -2,14 +2,13 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/cookie" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/locale" @@ -26,71 +25,71 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) { provider := request.RouteStringParam(r, "provider") if provider == "" { logger.Error("[OAuth2] Invalid or missing provider") - response.Redirect(w, r, route.Path(c.router, "login")) + html.Redirect(w, r, route.Path(c.router, "login")) return } code := request.QueryStringParam(r, "code", "") if code == "" { logger.Error("[OAuth2] No code received on callback") - response.Redirect(w, r, route.Path(c.router, "login")) + html.Redirect(w, r, route.Path(c.router, "login")) return } state := request.QueryStringParam(r, "state", "") if state == "" || state != request.OAuth2State(r) { logger.Error(`[OAuth2] Invalid state value: got "%s" instead of "%s"`, state, request.OAuth2State(r)) - response.Redirect(w, r, route.Path(c.router, "login")) + html.Redirect(w, r, route.Path(c.router, "login")) return } authProvider, err := getOAuth2Manager(c.cfg).Provider(provider) if err != nil { logger.Error("[OAuth2] %v", err) - response.Redirect(w, r, route.Path(c.router, "login")) + html.Redirect(w, r, route.Path(c.router, "login")) return } profile, err := authProvider.GetProfile(code) if err != nil { logger.Error("[OAuth2] %v", err) - response.Redirect(w, r, route.Path(c.router, "login")) + html.Redirect(w, r, route.Path(c.router, "login")) return } if request.IsAuthenticated(r) { user, err := c.store.UserByExtraField(profile.Key, profile.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if user != nil { logger.Error("[OAuth2] User #%d cannot be associated because %s is already associated", request.UserID(r), user.Username) sess.NewFlashErrorMessage(printer.Printf("error.duplicate_linked_account")) - response.Redirect(w, r, route.Path(c.router, "settings")) + html.Redirect(w, r, route.Path(c.router, "settings")) return } if err := c.store.UpdateExtraField(request.UserID(r), profile.Key, profile.ID); err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } sess.NewFlashMessage(printer.Printf("alert.account_linked")) - response.Redirect(w, r, route.Path(c.router, "settings")) + html.Redirect(w, r, route.Path(c.router, "settings")) return } user, err := c.store.UserByExtraField(profile.Key, profile.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if user == nil { if !c.cfg.IsOAuth2UserCreationAllowed() { - html.Forbidden(w) + html.Forbidden(w, r) return } @@ -100,14 +99,14 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) { user.Extra[profile.Key] = profile.ID if err := c.store.CreateUser(user); err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } } sessionToken, _, err := c.store.CreateUserSession(user.Username, r.UserAgent(), request.ClientIP(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -123,5 +122,5 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) { c.cfg.BasePath(), )) - response.Redirect(w, r, route.Path(c.router, "unread")) + html.Redirect(w, r, route.Path(c.router, "unread")) } diff --git a/ui/oauth2_redirect.go b/ui/oauth2_redirect.go index 90c20b1..e54309a 100644 --- a/ui/oauth2_redirect.go +++ b/ui/oauth2_redirect.go @@ -2,13 +2,13 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" + "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/logger" "miniflux.app/ui/session" @@ -21,16 +21,16 @@ func (c *Controller) OAuth2Redirect(w http.ResponseWriter, r *http.Request) { provider := request.RouteStringParam(r, "provider") if provider == "" { logger.Error("[OAuth2] Invalid or missing provider: %s", provider) - response.Redirect(w, r, route.Path(c.router, "login")) + html.Redirect(w, r, route.Path(c.router, "login")) return } authProvider, err := getOAuth2Manager(c.cfg).Provider(provider) if err != nil { logger.Error("[OAuth2] %v", err) - response.Redirect(w, r, route.Path(c.router, "login")) + html.Redirect(w, r, route.Path(c.router, "login")) return } - response.Redirect(w, r, authProvider.GetRedirectURL(sess.NewOAuth2State())) + html.Redirect(w, r, authProvider.GetRedirectURL(sess.NewOAuth2State())) } diff --git a/ui/oauth2_unlink.go b/ui/oauth2_unlink.go index 022e282..8e38ddc 100644 --- a/ui/oauth2_unlink.go +++ b/ui/oauth2_unlink.go @@ -2,13 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/locale" @@ -22,14 +21,14 @@ func (c *Controller) OAuth2Unlink(w http.ResponseWriter, r *http.Request) { provider := request.RouteStringParam(r, "provider") if provider == "" { logger.Info("[OAuth2] Invalid or missing provider") - response.Redirect(w, r, route.Path(c.router, "login")) + html.Redirect(w, r, route.Path(c.router, "login")) return } authProvider, err := getOAuth2Manager(c.cfg).Provider(provider) if err != nil { logger.Error("[OAuth2] %v", err) - response.Redirect(w, r, route.Path(c.router, "settings")) + html.Redirect(w, r, route.Path(c.router, "settings")) return } @@ -37,21 +36,21 @@ func (c *Controller) OAuth2Unlink(w http.ResponseWriter, r *http.Request) { hasPassword, err := c.store.HasPassword(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if !hasPassword { sess.NewFlashErrorMessage(printer.Printf("error.unlink_account_without_password")) - response.Redirect(w, r, route.Path(c.router, "settings")) + html.Redirect(w, r, route.Path(c.router, "settings")) return } if err := c.store.RemoveExtraField(request.UserID(r), authProvider.GetUserExtraKey()); err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } sess.NewFlashMessage(printer.Printf("alert.account_unlinked")) - response.Redirect(w, r, route.Path(c.router, "settings")) + html.Redirect(w, r, route.Path(c.router, "settings")) } diff --git a/ui/opml_export.go b/ui/opml_export.go index 20194b0..55ceb56 100644 --- a/ui/opml_export.go +++ b/ui/opml_export.go @@ -17,9 +17,9 @@ import ( func (c *Controller) Export(w http.ResponseWriter, r *http.Request) { opml, err := opml.NewHandler(c.store).Export(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } - xml.Attachment(w, "feeds.opml", opml) + xml.Attachment(w, r, "feeds.opml", opml) } diff --git a/ui/opml_import.go b/ui/opml_import.go index a8e732e..9a763ca 100644 --- a/ui/opml_import.go +++ b/ui/opml_import.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -17,7 +17,7 @@ import ( func (c *Controller) Import(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/opml_upload.go b/ui/opml_upload.go index 603b660..538f822 100644 --- a/ui/opml_upload.go +++ b/ui/opml_upload.go @@ -2,13 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/logger" @@ -21,14 +20,14 @@ import ( func (c *Controller) UploadOPML(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } file, fileHeader, err := r.FormFile("file") if err != nil { logger.Error("[Controller:UploadOPML] %v", err) - response.Redirect(w, r, route.Path(c.router, "import")) + html.Redirect(w, r, route.Path(c.router, "import")) return } defer file.Close() @@ -59,5 +58,5 @@ func (c *Controller) UploadOPML(w http.ResponseWriter, r *http.Request) { return } - response.Redirect(w, r, route.Path(c.router, "feeds")) + html.Redirect(w, r, route.Path(c.router, "feeds")) } diff --git a/ui/proxy.go b/ui/proxy.go index 553dcce..050c070 100644 --- a/ui/proxy.go +++ b/ui/proxy.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "encoding/base64" @@ -16,44 +16,47 @@ import ( "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" - "miniflux.app/logger" ) // ImageProxy fetch an image from a remote server and sent it back to the browser. func (c *Controller) ImageProxy(w http.ResponseWriter, r *http.Request) { - // If we receive a "If-None-Match" header we assume the image in stored in browser cache + // If we receive a "If-None-Match" header, we assume the image is already stored in browser cache. if r.Header.Get("If-None-Match") != "" { - response.NotModified(w) + w.WriteHeader(http.StatusNotModified) return } encodedURL := request.RouteStringParam(r, "encodedURL") if encodedURL == "" { - html.BadRequest(w, errors.New("No URL provided")) + html.BadRequest(w, r, errors.New("No URL provided")) return } decodedURL, err := base64.URLEncoding.DecodeString(encodedURL) if err != nil { - html.BadRequest(w, errors.New("Unable to decode this URL")) + html.BadRequest(w, r, errors.New("Unable to decode this URL")) return } clt := client.New(string(decodedURL)) resp, err := clt.Get() if err != nil { - logger.Error("[Controller:ImageProxy] %v", err) - html.NotFound(w) + html.ServerError(w, r, err) return } if resp.HasServerFailure() { - html.NotFound(w) + html.NotFound(w, r) return } body, _ := ioutil.ReadAll(resp.Body) etag := crypto.HashFromBytes(body) - response.Cache(w, r, resp.ContentType, etag, body, 72*time.Hour) + response.New(w ,r).WithCaching(etag, 72*time.Hour, func(b *response.Builder) { + b.WithHeader("Content-Type", resp.ContentType) + b.WithBody(body) + b.WithoutCompression() + b.Write() + }) } diff --git a/ui/search_entries.go b/ui/search_entries.go index e1dcbad..1304ef2 100644 --- a/ui/search_entries.go +++ b/ui/search_entries.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -19,7 +19,7 @@ import ( func (c *Controller) ShowSearchEntries(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -35,13 +35,13 @@ func (c *Controller) ShowSearchEntries(w http.ResponseWriter, r *http.Request) { entries, err := builder.GetEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } count, err := builder.CountEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/session_list.go b/ui/session_list.go index 3f5bf9e..76e693a 100644 --- a/ui/session_list.go +++ b/ui/session_list.go @@ -2,15 +2,15 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/request" + "miniflux.app/http/response/html" "miniflux.app/ui/session" "miniflux.app/ui/view" - "miniflux.app/http/response/html" ) // ShowSessions shows the list of active user sessions. @@ -20,13 +20,13 @@ func (c *Controller) ShowSessions(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } sessions, err := c.store.UserSessions(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/session_remove.go b/ui/session_remove.go index 27201fd..cc62612 100644 --- a/ui/session_remove.go +++ b/ui/session_remove.go @@ -8,7 +8,7 @@ import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" + "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/logger" ) @@ -21,5 +21,5 @@ func (c *Controller) RemoveSession(w http.ResponseWriter, r *http.Request) { logger.Error("[Controller:RemoveSession] %v", err) } - response.Redirect(w, r, route.Path(c.router, "sessions")) + html.Redirect(w, r, route.Path(c.router, "sessions")) } diff --git a/ui/settings_show.go b/ui/settings_show.go index 07703eb..4f4756d 100644 --- a/ui/settings_show.go +++ b/ui/settings_show.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -23,7 +23,7 @@ func (c *Controller) ShowSettings(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -37,7 +37,7 @@ func (c *Controller) ShowSettings(w http.ResponseWriter, r *http.Request) { timezones, err := c.store.Timezones() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/settings_update.go b/ui/settings_update.go index ed424e3..466bb78 100644 --- a/ui/settings_update.go +++ b/ui/settings_update.go @@ -2,12 +2,11 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/request" "miniflux.app/http/route" @@ -26,13 +25,13 @@ func (c *Controller) UpdateSettings(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } timezones, err := c.store.Timezones() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -70,5 +69,5 @@ func (c *Controller) UpdateSettings(w http.ResponseWriter, r *http.Request) { sess.SetLanguage(user.Language) sess.SetTheme(user.Theme) sess.NewFlashMessage(locale.NewPrinter(request.UserLanguage(r)).Printf("alert.prefs_saved")) - response.Redirect(w, r, route.Path(c.router, "settings")) + html.Redirect(w, r, route.Path(c.router, "settings")) } diff --git a/ui/static_app_icon.go b/ui/static_app_icon.go index 2ad42fd..9e2a448 100644 --- a/ui/static_app_icon.go +++ b/ui/static_app_icon.go @@ -12,26 +12,28 @@ import ( "miniflux.app/http/request" "miniflux.app/http/response" "miniflux.app/http/response/html" - "miniflux.app/logger" "miniflux.app/ui/static" ) -// AppIcon renders application icons. +// AppIcon shows application icons. func (c *Controller) AppIcon(w http.ResponseWriter, r *http.Request) { filename := request.RouteStringParam(r, "filename") - encodedBlob, found := static.Binaries[filename] + etag, found := static.BinariesChecksums[filename] if !found { - logger.Info("[Controller:AppIcon] This icon doesn't exists: %s", filename) - html.NotFound(w) + html.NotFound(w, r) return } - blob, err := base64.StdEncoding.DecodeString(encodedBlob) - if err != nil { - logger.Error("[Controller:AppIcon] %v", err) - html.NotFound(w) - return - } + response.New(w, r).WithCaching(etag, 72*time.Hour, func(b *response.Builder) { + blob, err := base64.StdEncoding.DecodeString(static.Binaries[filename]) + if err != nil { + html.ServerError(w, r, err) + return + } - response.Cache(w, r, "image/png", static.BinariesChecksums[filename], blob, 48*time.Hour) + b.WithHeader("Content-Type", "image/png") + b.WithoutCompression() + b.WithBody(blob) + b.Write() + }) } diff --git a/ui/static_favicon.go b/ui/static_favicon.go index 2e19c05..1266a19 100644 --- a/ui/static_favicon.go +++ b/ui/static_favicon.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "encoding/base64" @@ -11,18 +11,27 @@ import ( "miniflux.app/http/response" "miniflux.app/http/response/html" - "miniflux.app/logger" "miniflux.app/ui/static" ) -// Favicon renders the application favicon. +// Favicon shows the application favicon. func (c *Controller) Favicon(w http.ResponseWriter, r *http.Request) { - blob, err := base64.StdEncoding.DecodeString(static.Binaries["favicon.ico"]) - if err != nil { - logger.Error("[Controller:Favicon] %v", err) - html.NotFound(w) + etag, found := static.BinariesChecksums["favicon.ico"] + if !found { + html.NotFound(w, r) return } - response.Cache(w, r, "image/x-icon", static.BinariesChecksums["favicon.ico"], blob, 48*time.Hour) + response.New(w, r).WithCaching(etag, 48*time.Hour, func(b *response.Builder) { + blob, err := base64.StdEncoding.DecodeString(static.Binaries["favicon.ico"]) + if err != nil { + html.ServerError(w, r, err) + return + } + + b.WithHeader("Content-Type", "image/x-icon") + b.WithoutCompression() + b.WithBody(blob) + b.Write() + }) } diff --git a/ui/static_javascript.go b/ui/static_javascript.go index 248fae3..ff7fd16 100644 --- a/ui/static_javascript.go +++ b/ui/static_javascript.go @@ -17,13 +17,15 @@ import ( // Javascript renders application client side code. func (c *Controller) Javascript(w http.ResponseWriter, r *http.Request) { filename := request.RouteStringParam(r, "name") - if _, found := static.Javascripts[filename]; !found { - html.NotFound(w) + etag, found := static.JavascriptsChecksums[filename] + if !found { + html.NotFound(w, r) return } - body := static.Javascripts[filename] - etag := static.JavascriptsChecksums[filename] - - response.Cache(w, r, "text/javascript; charset=utf-8", etag, []byte(body), 48*time.Hour) + response.New(w, r).WithCaching(etag, 48*time.Hour, func(b *response.Builder) { + b.WithHeader("Content-Type", "text/javascript; charset=utf-8") + b.WithBody(static.Javascripts[filename]) + b.Write() + }) } diff --git a/ui/static_stylesheet.go b/ui/static_stylesheet.go index 8e475bd..9a21bc6 100644 --- a/ui/static_stylesheet.go +++ b/ui/static_stylesheet.go @@ -16,14 +16,16 @@ import ( // Stylesheet renders the CSS. func (c *Controller) Stylesheet(w http.ResponseWriter, r *http.Request) { - stylesheet := request.RouteStringParam(r, "name") - if _, found := static.Stylesheets[stylesheet]; !found { - html.NotFound(w) + filename := request.RouteStringParam(r, "name") + etag, found := static.StylesheetsChecksums[filename] + if !found { + html.NotFound(w, r) return } - body := static.Stylesheets[stylesheet] - etag := static.StylesheetsChecksums[stylesheet] - - response.Cache(w, r, "text/css; charset=utf-8", etag, []byte(body), 48*time.Hour) + response.New(w, r).WithCaching(etag, 48*time.Hour, func(b *response.Builder) { + b.WithHeader("Content-Type", "text/css; charset=utf-8") + b.WithBody(static.Stylesheets[filename]) + b.Write() + }) } diff --git a/ui/subscription_add.go b/ui/subscription_add.go index 387f340..3056eec 100644 --- a/ui/subscription_add.go +++ b/ui/subscription_add.go @@ -21,13 +21,13 @@ func (c *Controller) AddSubscription(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } categories, err := c.store.Categories(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/subscription_bookmarklet.go b/ui/subscription_bookmarklet.go index cba039a..5c0e08c 100644 --- a/ui/subscription_bookmarklet.go +++ b/ui/subscription_bookmarklet.go @@ -22,13 +22,13 @@ func (c *Controller) Bookmarklet(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } categories, err := c.store.Categories(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/subscription_choose.go b/ui/subscription_choose.go index 10e46ad..4f701c8 100644 --- a/ui/subscription_choose.go +++ b/ui/subscription_choose.go @@ -2,13 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/client" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/request" "miniflux.app/http/route" @@ -24,13 +23,13 @@ func (c *Controller) ChooseSubscription(w http.ResponseWriter, r *http.Request) user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } categories, err := c.store.Categories(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -65,5 +64,5 @@ func (c *Controller) ChooseSubscription(w http.ResponseWriter, r *http.Request) return } - response.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID)) + html.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID)) } diff --git a/ui/subscription_submit.go b/ui/subscription_submit.go index d1cefbd..801e516 100644 --- a/ui/subscription_submit.go +++ b/ui/subscription_submit.go @@ -8,7 +8,6 @@ import ( "net/http" "miniflux.app/http/client" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/request" "miniflux.app/http/route" @@ -26,13 +25,13 @@ func (c *Controller) SubmitSubscription(w http.ResponseWriter, r *http.Request) user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } categories, err := c.store.Categories(user.ID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -90,7 +89,7 @@ func (c *Controller) SubmitSubscription(w http.ResponseWriter, r *http.Request) return } - response.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID)) + html.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID)) case n > 1: v := view.New(c.tpl, r, sess) v.Set("subscriptions", subscriptions) diff --git a/ui/unread_entries.go b/ui/unread_entries.go index 5992162..cb02428 100644 --- a/ui/unread_entries.go +++ b/ui/unread_entries.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -22,7 +22,7 @@ func (c *Controller) ShowUnreadPage(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -31,7 +31,7 @@ func (c *Controller) ShowUnreadPage(w http.ResponseWriter, r *http.Request) { builder.WithStatus(model.EntryStatusUnread) countUnread, err := builder.CountEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } @@ -47,7 +47,7 @@ func (c *Controller) ShowUnreadPage(w http.ResponseWriter, r *http.Request) { builder.WithLimit(nbItemsPerPage) entries, err := builder.GetEntries() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/unread_mark_all_read.go b/ui/unread_mark_all_read.go index c467923..724da67 100644 --- a/ui/unread_mark_all_read.go +++ b/ui/unread_mark_all_read.go @@ -8,7 +8,7 @@ import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" + "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/logger" ) @@ -19,5 +19,5 @@ func (c *Controller) MarkAllAsRead(w http.ResponseWriter, r *http.Request) { logger.Error("[MarkAllAsRead] %v", err) } - response.Redirect(w, r, route.Path(c.router, "unread")) + html.Redirect(w, r, route.Path(c.router, "unread")) } diff --git a/ui/user_create.go b/ui/user_create.go index b31b0de..a94d286 100644 --- a/ui/user_create.go +++ b/ui/user_create.go @@ -21,12 +21,12 @@ func (c *Controller) CreateUser(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if !user.IsAdmin { - html.Forbidden(w) + html.Forbidden(w, r) return } diff --git a/ui/user_edit.go b/ui/user_edit.go index f2c1abf..2348a7d 100644 --- a/ui/user_edit.go +++ b/ui/user_edit.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -21,24 +21,24 @@ func (c *Controller) EditUser(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if !user.IsAdmin { - html.Forbidden(w) + html.Forbidden(w, r) return } userID := request.RouteInt64Param(r, "userID") selectedUser, err := c.store.UserByID(userID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if selectedUser == nil { - html.NotFound(w) + html.NotFound(w, r) return } diff --git a/ui/user_list.go b/ui/user_list.go index dce30e0..3c9e3ed 100644 --- a/ui/user_list.go +++ b/ui/user_list.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" @@ -20,18 +20,18 @@ func (c *Controller) ShowUsers(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if !user.IsAdmin { - html.Forbidden(w) + html.Forbidden(w, r) return } users, err := c.store.Users() if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } diff --git a/ui/user_remove.go b/ui/user_remove.go index 981a7a2..beda7be 100644 --- a/ui/user_remove.go +++ b/ui/user_remove.go @@ -8,7 +8,6 @@ import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" ) @@ -17,31 +16,31 @@ import ( func (c *Controller) RemoveUser(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if !user.IsAdmin { - html.Forbidden(w) + html.Forbidden(w, r) return } userID := request.RouteInt64Param(r, "userID") selectedUser, err := c.store.UserByID(userID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if selectedUser == nil { - html.NotFound(w) + html.NotFound(w, r) return } if err := c.store.RemoveUser(selectedUser.ID); err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } - response.Redirect(w, r, route.Path(c.router, "users")) + html.Redirect(w, r, route.Path(c.router, "users")) } diff --git a/ui/user_save.go b/ui/user_save.go index 7c3685b..a4be346 100644 --- a/ui/user_save.go +++ b/ui/user_save.go @@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui" import ( "net/http" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/request" "miniflux.app/http/route" @@ -21,12 +20,12 @@ import ( func (c *Controller) SaveUser(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if !user.IsAdmin { - html.Forbidden(w) + html.Forbidden(w, r) return } @@ -60,5 +59,5 @@ func (c *Controller) SaveUser(w http.ResponseWriter, r *http.Request) { return } - response.Redirect(w, r, route.Path(c.router, "users")) + html.Redirect(w, r, route.Path(c.router, "users")) } diff --git a/ui/user_update.go b/ui/user_update.go index 006d49a..34567e0 100644 --- a/ui/user_update.go +++ b/ui/user_update.go @@ -2,13 +2,12 @@ // Use of this source code is governed by the Apache 2.0 // license that can be found in the LICENSE file. -package ui // import "miniflux.app/ui" +package ui // import "miniflux.app/ui" import ( "net/http" "miniflux.app/http/request" - "miniflux.app/http/response" "miniflux.app/http/response/html" "miniflux.app/http/route" "miniflux.app/logger" @@ -21,24 +20,24 @@ import ( func (c *Controller) UpdateUser(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(request.UserID(r)) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if !user.IsAdmin { - html.Forbidden(w) + html.Forbidden(w, r) return } userID := request.RouteInt64Param(r, "userID") selectedUser, err := c.store.UserByID(userID) if err != nil { - html.ServerError(w, err) + html.ServerError(w, r, err) return } if selectedUser == nil { - html.NotFound(w) + html.NotFound(w, r) return } @@ -73,5 +72,5 @@ func (c *Controller) UpdateUser(w http.ResponseWriter, r *http.Request) { return } - response.Redirect(w, r, route.Path(c.router, "users")) + html.Redirect(w, r, route.Path(c.router, "users")) } -- cgit v1.2.3