Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
2be0dc40
Commit
2be0dc40
authored
Mar 09, 2017
by
Matt Holt
Committed by
GitHub
Mar 09, 2017
Browse files
Options
Browse Files
Download
Plain Diff
templates: Merge pull request #1482 from crvv/master
templates: Set MIME type
parents
e3e62a95
4a095590
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
0 deletions
+11
-0
caddyhttp/templates/templates.go
caddyhttp/templates/templates.go
+11
-0
No files found.
caddyhttp/templates/templates.go
View file @
2be0dc40
...
...
@@ -4,6 +4,7 @@ package templates
import
(
"bytes"
"mime"
"net/http"
"os"
"path"
...
...
@@ -62,6 +63,16 @@ func (t Templates) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
return
http
.
StatusInternalServerError
,
err
}
// If Content-Type isn't set here, http.ResponseWriter.Write
// will set it according to response body. But other middleware
// such as gzip can modify response body, then Content-Type
// detected by http.ResponseWriter.Write is wrong.
ctype
:=
mime
.
TypeByExtension
(
ext
)
if
ctype
==
""
{
ctype
=
http
.
DetectContentType
(
buf
.
Bytes
())
}
w
.
Header
()
.
Set
(
"Content-Type"
,
ctype
)
templateInfo
,
err
:=
os
.
Stat
(
templatePath
)
if
err
==
nil
{
// add the Last-Modified header if we were able to read the stamp
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment