Skip to content

Commit

Permalink
code improvement, cleanup, godoc
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Jun 2, 2017
1 parent 27e9274 commit 689f1c6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 118 deletions.
2 changes: 1 addition & 1 deletion ahttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package ahttp
import "net/http"

// Version no. of aah framework ahttp library
const Version = "0.6"
const Version = "0.7"

// HTTP Method names
const (
Expand Down
18 changes: 18 additions & 0 deletions content_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ var (
},
}

// ContentTypeJSONText JSON text content type.
ContentTypeJSONText = &ContentType{
Mime: "text/json",
Exts: []string{".json"},
Params: map[string]string{
"charset": "utf-8",
},
}

// ContentTypeXML XML content type.
ContentTypeXML = &ContentType{
Mime: "application/xml",
Expand All @@ -37,6 +46,15 @@ var (
},
}

// ContentTypeXMLText XML text content type.
ContentTypeXMLText = &ContentType{
Mime: "text/xml",
Exts: []string{".xml"},
Params: map[string]string{
"charset": "utf-8",
},
}

// ContentTypeMultipartForm form data and File.
ContentTypeMultipartForm = &ContentType{
Mime: "multipart/form-data",
Expand Down
61 changes: 0 additions & 61 deletions fs.go

This file was deleted.

54 changes: 0 additions & 54 deletions fs_test.go

This file was deleted.

1 change: 1 addition & 0 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func NegotiateContentType(req *http.Request) *ContentType {
// 2) From Accept header
spec := ParseAccept(req, HeaderAccept).MostQualified()
if spec == nil {
// if parsed spec is nil return content type as HTML.
return ContentTypeHTML
}

Expand Down
9 changes: 8 additions & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type (
// instance from Go HTTP request.
func ParseRequest(r *http.Request, req *Request) *Request {
req.Schema = identifyScheme(r)
req.Host = r.Host
req.Host = host(r)
req.Method = r.Method
req.Path = r.URL.Path
req.Header = r.Header
Expand Down Expand Up @@ -303,6 +303,13 @@ func clientIP(req *http.Request) string {
return ""
}

func host(r *http.Request) string {
if ess.IsStrEmpty(r.URL.Host) {
return r.Host
}
return r.URL.Host
}

func getReferer(hdr http.Header) string {
referer := hdr.Get(HeaderReferer)

Expand Down
2 changes: 1 addition & 1 deletion request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestHTTPParseRequest(t *testing.T) {
req.Header.Add(HeaderAccept, "application/json;charset=utf-8")
req.Header.Add(HeaderReferer, "http://localhost:8080/home.html")
req.Header.Add(HeaderAcceptLanguage, "en-gb;leve=1;q=0.8, da, en;level=2;q=0.7, en-us;q=gg")
req.URL, _ = url.Parse("http://localhost:8080/welcome1.html?_ref=true")
req.URL, _ = url.Parse("/welcome1.html?_ref=true")

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

Expand Down

0 comments on commit 689f1c6

Please sign in to comment.