mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2026-10-19 16:14:39 +00:00
chore (optimisation): micro optimisations
This commit is contained in:
@@ -81,7 +81,7 @@ func FileCat(ctx *App, res http.ResponseWriter, req *http.Request) {
|
||||
var mtime string
|
||||
if req.Header.Get("Range") != "" {
|
||||
if finfo, err := ctx.Backend.Stat(path); err == nil {
|
||||
mtime = fmt.Sprintf("%d", finfo.ModTime().Unix())
|
||||
mtime = strconv.FormatInt(finfo.ModTime().Unix(), 10)
|
||||
}
|
||||
ctx.Session["fullpath"] = path
|
||||
if p := fileCache.Get(ctx.Session); p != nil {
|
||||
@@ -254,7 +254,7 @@ func FileCat(ctx *App, res http.ResponseWriter, req *http.Request) {
|
||||
|
||||
// publish headers
|
||||
if contentLength >= 0 {
|
||||
header.Set("Content-Length", fmt.Sprintf("%d", contentLength))
|
||||
header.Set("Content-Length", strconv.FormatInt(contentLength, 10))
|
||||
}
|
||||
if disable_csp() == false {
|
||||
header.Set("Content-Security-Policy", "default-src 'none'; img-src 'self'; media-src 'self'; style-src 'unsafe-inline'; font-src data:; script-src-elem 'self'")
|
||||
@@ -288,7 +288,7 @@ func FileCat(ctx *App, res http.ResponseWriter, req *http.Request) {
|
||||
if f, ok := file.(io.ReadSeeker); ok && len(ranges) > 0 {
|
||||
if _, err = f.Seek(ranges[0][0], io.SeekStart); err == nil {
|
||||
header.Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", ranges[0][0], ranges[0][1], contentLength))
|
||||
header.Set("Content-Length", fmt.Sprintf("%d", ranges[0][1]-ranges[0][0]+1))
|
||||
header.Set("Content-Length", strconv.FormatInt(ranges[0][1]-ranges[0][0]+1, 10))
|
||||
res.WriteHeader(http.StatusPartialContent)
|
||||
io.CopyBuffer(res, io.LimitReader(f, ranges[0][1]-ranges[0][0]+1), *buf)
|
||||
} else {
|
||||
|
||||
@@ -110,7 +110,7 @@ func SecureOrigin(fn HandlerFunc) HandlerFunc {
|
||||
if host := Config.Get("general.host").String(); host != "" {
|
||||
host = strings.TrimPrefix(host, "http://")
|
||||
host = strings.TrimPrefix(host, "https://")
|
||||
if req.Host != host && req.Host != fmt.Sprintf("%s:443", host) {
|
||||
if req.Host != host && req.Host != host+":443" {
|
||||
if strings.HasPrefix(req.URL.Path, "/admin/") == false {
|
||||
Log.Error("Request coming from \"%s\" was blocked, only traffic from \"%s\" is allowed. You can change this from the admin console under configure -> host", req.Host, host)
|
||||
SendErrorResult(res, ErrNotAllowed)
|
||||
|
||||
@@ -194,7 +194,7 @@ func decompress(something []byte) ([]byte, error) {
|
||||
// Create a unique ID that can be use to identify different session
|
||||
func GenerateID(params map[string]string) string {
|
||||
p := ""
|
||||
orderedKeys := make([]string, len(params))
|
||||
orderedKeys := make([]string, 0, len(params))
|
||||
for key, _ := range params {
|
||||
orderedKeys = append(orderedKeys, key)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -48,7 +47,7 @@ type AppError struct {
|
||||
}
|
||||
|
||||
func (e AppError) Error() string {
|
||||
return fmt.Sprintf("%s", e.message)
|
||||
return e.message
|
||||
}
|
||||
func (e AppError) Status() int {
|
||||
return e.status
|
||||
|
||||
Reference in New Issue
Block a user