Skip to content

Commit

Permalink
http: set content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Mar 20, 2024
1 parent 8fca648 commit b8bf38f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion http/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package http
import (
"context"
"errors"
"mime"
"net/http"
"net/url"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -108,6 +110,15 @@ func buildDispositionHeader(params url.Values) string {
return disposition
}

func getFileName(path []string, params url.Values) string {
if filename, ok := params["filename"]; ok {
return mime.TypeByExtension(filepath.Ext(filename[0]))
} else if len(path) > 0 {
return mime.TypeByExtension(filepath.Ext(path[len(path)-1]))
}
return ""
}

func (is *ipfsGatewayServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down Expand Up @@ -179,7 +190,7 @@ func (is *ipfsGatewayServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
defer rsc.Close()
http.ServeContent(w, r, "", time.Now(), rsc)
http.ServeContent(w, r, getFileName(path, query), time.Now(), rsc)
}
}

Expand Down

0 comments on commit b8bf38f

Please sign in to comment.