Accept ext on entity files to set content type in resp
parent
3a3ee3912d
commit
4d8f75f7c9
|
|
@ -4,9 +4,11 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"local/dndex/config"
|
||||
"local/simpleserve/simpleserve"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
|
@ -95,6 +97,8 @@ func (rest *REST) filesDelete(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (rest *REST) filesGet(w http.ResponseWriter, r *http.Request) {
|
||||
simpleserve.SetContentTypeIfMedia(w, r)
|
||||
r.URL.Path = strings.TrimSuffix(r.URL.Path, path.Ext(r.URL.Path))
|
||||
localPath := rest.filesPath(r)
|
||||
if stat, err := os.Stat(localPath); os.IsNotExist(err) {
|
||||
rest.respNotFound(w)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
|
|
@ -12,14 +13,17 @@ import (
|
|||
|
||||
func TestFiles(t *testing.T) {
|
||||
cases := map[string]func(*testing.T, *REST, func(*http.Request)){
|
||||
"create-get": func(t *testing.T, rest *REST, scope func(r *http.Request)) {
|
||||
"create-get w/ content type": func(t *testing.T, rest *REST, scope func(r *http.Request)) {
|
||||
content := uuid.New().String()
|
||||
w := testFilesPost(t, rest, scope, content)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatal(w.Code, string(w.Body.Bytes()))
|
||||
}
|
||||
s := string(w.Body.Bytes())
|
||||
s := fmt.Sprintf("%s.jpg", w.Body.Bytes())
|
||||
w = testFilesGet(t, rest, s, scope)
|
||||
if w.Header().Get("Content-Type") != "image/jpeg" {
|
||||
t.Fatal(w.Header())
|
||||
}
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatal(w.Code, string(w.Body.Bytes()))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue