Skip to content

Commit 9ab8efd

Browse files
committed
proto field added, content type check improved, version bump
1 parent 62452f6 commit 9ab8efd

6 files changed

+11
-6
lines changed

ahttp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
// Version no. of aah framework ahttp library
15-
const Version = "0.9"
15+
const Version = "0.10"
1616

1717
// HTTP Method names
1818
const (

content_type.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type (
5555
// E.g.:
5656
// contentType.IsEqual("application/json")
5757
func (c *ContentType) IsEqual(contentType string) bool {
58-
return strings.HasPrefix(c.Raw(), strings.ToLower(contentType))
58+
return strings.HasPrefix(c.String(), strings.ToLower(contentType))
5959
}
6060

6161
// Charset method returns charset of content-type

gzip_response.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var (
4646

4747
// GetGzipResponseWriter wraps `http.ResponseWriter`, returns aah framework response
4848
// writer that allows to advantage of response process.
49-
// Deprecated use `AcquireResponseWriter` instead.
49+
// Deprecated use `WrapGzipWriter` instead.
5050
func GetGzipResponseWriter(w ResponseWriter) ResponseWriter {
5151
gr := grPool.Get().(*GzipResponse)
5252
gr.gw = acquireGzipWriter(w)

request.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type (
3535
// Host value of the HTTP 'Host' header (e.g. 'example.com:8080').
3636
Host string
3737

38+
// Proto value of the current HTTP request protocol. (e.g. HTTP/1.1, HTTP/2.0)
39+
Proto string
40+
3841
// Method request method e.g. `GET`, `POST`, etc.
3942
Method string
4043

@@ -110,6 +113,7 @@ type (
110113
func ParseRequest(r *http.Request, req *Request) *Request {
111114
req.Scheme = identifyScheme(r)
112115
req.Host = host(r)
116+
req.Proto = r.Proto
113117
req.Method = r.Method
114118
req.Path = r.URL.Path
115119
req.Header = r.Header
@@ -196,6 +200,7 @@ func (r *Request) Unwrap() *http.Request {
196200
func (r *Request) Reset() {
197201
r.Scheme = ""
198202
r.Host = ""
203+
r.Proto = ""
199204
r.Method = ""
200205
r.Path = ""
201206
r.Header = nil
@@ -269,7 +274,7 @@ func (p *Params) FormFile(key string) (multipart.File, *multipart.FileHeader, er
269274
f, err := fh[0].Open()
270275
return f, fh[0], err
271276
}
272-
return nil, nil, fmt.Errorf("error file is missing: %s", key)
277+
return nil, nil, fmt.Errorf("ahttp: no such key/file: %s", key)
273278
}
274279
return nil, nil, nil
275280
}

request_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestHTTPRequestParams(t *testing.T) {
143143
req3.Header.Add(HeaderContentType, ContentTypeMultipartForm.String())
144144
aahReq3 := AcquireRequest(req3)
145145
aahReq3.Params.File = make(map[string][]*multipart.FileHeader)
146-
aahReq3.Params.File["testfile.txt"] = []*multipart.FileHeader{&multipart.FileHeader{Filename: "testfile.txt"}}
146+
aahReq3.Params.File["testfile.txt"] = []*multipart.FileHeader{{Filename: "testfile.txt"}}
147147
f, fh, err := aahReq3.FormFile("testfile.txt")
148148
assert.Nil(t, f)
149149
assert.Equal(t, "testfile.txt", fh.Filename)

response.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (r *Response) Reset() {
171171
//___________________________________
172172

173173
func (r *Response) setContentTypeIfNotSet(b []byte) {
174-
if _, found := r.Header()[HeaderContentType]; !found {
174+
if ct := r.Header().Get(HeaderContentType); ess.IsStrEmpty(ct) {
175175
r.Header().Set(HeaderContentType, http.DetectContentType(b))
176176
}
177177
}

0 commit comments

Comments
 (0)