2018-04-30 01:35:04 +02:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
package html // import "miniflux.app/http/response/html"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
"miniflux.app/http/response"
|
|
|
|
"miniflux.app/logger"
|
2018-04-30 01:35:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// OK writes a standard HTML response.
|
2018-07-07 05:39:28 +02:00
|
|
|
func OK(w http.ResponseWriter, r *http.Request, b []byte) {
|
2018-04-30 01:35:04 +02:00
|
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
2018-07-07 05:39:28 +02:00
|
|
|
response.Compress(w, r, b)
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ServerError sends a 500 error to the browser.
|
|
|
|
func ServerError(w http.ResponseWriter, err error) {
|
|
|
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("[Internal Server Error] %v", err)
|
|
|
|
w.Write([]byte("Internal Server Error: " + err.Error()))
|
|
|
|
} else {
|
|
|
|
w.Write([]byte("Internal Server Error"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BadRequest sends a 400 error to the browser.
|
|
|
|
func BadRequest(w http.ResponseWriter, err error) {
|
|
|
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("[Bad Request] %v", err)
|
|
|
|
w.Write([]byte("Bad Request: " + err.Error()))
|
|
|
|
} else {
|
|
|
|
w.Write([]byte("Bad Request"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NotFound sends a 404 error to the browser.
|
|
|
|
func NotFound(w http.ResponseWriter) {
|
|
|
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
w.Write([]byte("Page Not Found"))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forbidden sends a 403 error to the browser.
|
|
|
|
func Forbidden(w http.ResponseWriter) {
|
|
|
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
|
|
|
w.WriteHeader(http.StatusForbidden)
|
|
|
|
w.Write([]byte("Access Forbidden"))
|
|
|
|
}
|