This commit is contained in:
parent
2b1c2a3c46
commit
857eee205c
2 changed files with 17 additions and 5 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
forgejo-pages
|
||||||
11
lib/web.go
11
lib/web.go
|
|
@ -12,6 +12,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
"mime"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Forgejo struct {
|
type Forgejo struct {
|
||||||
|
|
@ -129,6 +131,15 @@ func (f *Forgejo) handle(w http.ResponseWriter, r *http.Request) {
|
||||||
trySet(w.Header(), "Last-Modified", resp.Header)
|
trySet(w.Header(), "Last-Modified", resp.Header)
|
||||||
trySet(w.Header(), "Content-Length", resp.Header)
|
trySet(w.Header(), "Content-Length", resp.Header)
|
||||||
trySet(w.Header(), "Content-Range", resp.Header)
|
trySet(w.Header(), "Content-Range", resp.Header)
|
||||||
|
contentType := resp.Header.Get("Content-Type")
|
||||||
|
if contentType == "" || strings.HasPrefix(contentType, "text/plain") {
|
||||||
|
if ct := mime.TypeByExtension(filepath.Ext(file)); ct != "" {
|
||||||
|
contentType = ct
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if contentType != "" {
|
||||||
|
w.Header().Set("Content-Type", contentType)
|
||||||
|
}
|
||||||
|
|
||||||
w.WriteHeader(resp.StatusCode)
|
w.WriteHeader(resp.StatusCode)
|
||||||
io.Copy(w, resp.Body)
|
io.Copy(w, resp.Body)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue