1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00

Content type based on processiong options

This commit is contained in:
DarthSim 2017-07-06 03:09:41 +06:00
parent 2e6b7288e4
commit 842d46fe66

View File

@ -1,21 +1,27 @@
package main
import (
"bytes"
"compress/gzip"
"crypto/subtle"
"encoding/base64"
"errors"
"fmt"
"image"
"log"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"github.com/h2non/bimg"
)
var mimes = map[bimg.ImageType]string{
bimg.JPEG: "image/jpeg",
bimg.PNG: "image/png",
bimg.WEBP: "image/webp",
}
type httpHandler struct {
sem chan struct{}
}
@ -77,11 +83,6 @@ func parsePath(r *http.Request) (string, processingOptions, error) {
return string(filename), po, nil
}
func imageContentType(b []byte) string {
_, imgtype, _ := image.DecodeConfig(bytes.NewReader(b))
return fmt.Sprintf("image/%s", imgtype)
}
func logResponse(status int, msg string) {
var color int
@ -101,7 +102,7 @@ func respondWithImage(r *http.Request, rw http.ResponseWriter, data []byte, imgU
rw.Header().Set("Expires", time.Now().Add(time.Second*time.Duration(conf.TTL)).Format(http.TimeFormat))
rw.Header().Set("Cache-Control", fmt.Sprintf("Cache-Control: max-age=%d", conf.TTL))
rw.Header().Set("Content-Type", imageContentType(data))
rw.Header().Set("Content-Type", mimes[po.format])
if gzipped {
rw.Header().Set("Content-Encoding", "gzip")
}