Skip to content

Commit 9b346bd

Browse files
committed
Based on the "extension" of the requested path, returns an appropriate content type
closes revel#963, revel#1045
1 parent 23418a6 commit 9b346bd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

http.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414

1515
"golang.org/x/net/websocket"
16+
"path/filepath"
1617
)
1718

1819
// Request Revel's HTTP request object structure
@@ -78,6 +79,18 @@ func ResolveContentType(req *http.Request) string {
7879
// returning a default of "html" when Accept header cannot be mapped to a
7980
// value above.
8081
func ResolveFormat(req *http.Request) string {
82+
ext := strings.ToLower(filepath.Ext(req.URL.Path))
83+
switch ext {
84+
case ".html":
85+
return "html"
86+
case ".json":
87+
return "json"
88+
case ".xml":
89+
return "xml"
90+
case ".txt":
91+
return "txt"
92+
}
93+
8194
accept := req.Header.Get("accept")
8295

8396
switch {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy