Skip to content

Commit 689f1c6

Browse files
committed
code improvement, cleanup, godoc
1 parent 27e9274 commit 689f1c6

7 files changed

+29
-118
lines changed

ahttp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package ahttp
99
import "net/http"
1010

1111
// Version no. of aah framework ahttp library
12-
const Version = "0.6"
12+
const Version = "0.7"
1313

1414
// HTTP Method names
1515
const (

content_type.go

+18
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ var (
2828
},
2929
}
3030

31+
// ContentTypeJSONText JSON text content type.
32+
ContentTypeJSONText = &ContentType{
33+
Mime: "text/json",
34+
Exts: []string{".json"},
35+
Params: map[string]string{
36+
"charset": "utf-8",
37+
},
38+
}
39+
3140
// ContentTypeXML XML content type.
3241
ContentTypeXML = &ContentType{
3342
Mime: "application/xml",
@@ -37,6 +46,15 @@ var (
3746
},
3847
}
3948

49+
// ContentTypeXMLText XML text content type.
50+
ContentTypeXMLText = &ContentType{
51+
Mime: "text/xml",
52+
Exts: []string{".xml"},
53+
Params: map[string]string{
54+
"charset": "utf-8",
55+
},
56+
}
57+
4058
// ContentTypeMultipartForm form data and File.
4159
ContentTypeMultipartForm = &ContentType{
4260
Mime: "multipart/form-data",

fs.go

-61
This file was deleted.

fs_test.go

-54
This file was deleted.

header.go

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func NegotiateContentType(req *http.Request) *ContentType {
122122
// 2) From Accept header
123123
spec := ParseAccept(req, HeaderAccept).MostQualified()
124124
if spec == nil {
125+
// if parsed spec is nil return content type as HTML.
125126
return ContentTypeHTML
126127
}
127128

request.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type (
100100
// instance from Go HTTP request.
101101
func ParseRequest(r *http.Request, req *Request) *Request {
102102
req.Schema = identifyScheme(r)
103-
req.Host = r.Host
103+
req.Host = host(r)
104104
req.Method = r.Method
105105
req.Path = r.URL.Path
106106
req.Header = r.Header
@@ -303,6 +303,13 @@ func clientIP(req *http.Request) string {
303303
return ""
304304
}
305305

306+
func host(r *http.Request) string {
307+
if ess.IsStrEmpty(r.URL.Host) {
308+
return r.Host
309+
}
310+
return r.URL.Host
311+
}
312+
306313
func getReferer(hdr http.Header) string {
307314
referer := hdr.Get(HeaderReferer)
308315

request_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestHTTPParseRequest(t *testing.T) {
5555
req.Header.Add(HeaderAccept, "application/json;charset=utf-8")
5656
req.Header.Add(HeaderReferer, "http://localhost:8080/home.html")
5757
req.Header.Add(HeaderAcceptLanguage, "en-gb;leve=1;q=0.8, da, en;level=2;q=0.7, en-us;q=gg")
58-
req.URL, _ = url.Parse("http://localhost:8080/welcome1.html?_ref=true")
58+
req.URL, _ = url.Parse("/welcome1.html?_ref=true")
5959

6060
aahReq := ParseRequest(req, &Request{})
6161

0 commit comments

Comments
 (0)