Skip to content

Commit

Permalink
Merge pull request #20 for v0.11.2 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Jul 28, 2018
2 parents 4850032 + 17b990a commit 266c519
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<h2 align="center">HTTP extension library by aah framework</h2>
</p>
<p align="center">
<p align="center"><a href="https://travis-ci.org/go-aah/ahttp"><img src="https://travis-ci.org/go-aah/ahttp.svg?branch=master" alt="Build Status"></a> <a href="https://codecov.io/gh/go-aah/ahttp/branch/master"><img src="https://codecov.io/gh/go-aah/ahttp/branch/master/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/aahframework.org/ahttp.v0"><img src="https://goreportcard.com/badge/aahframework.org/ahttp.v0" alt="Go Report Card"></a> <a href="https://github.com/go-aah/ahttp/releases/latest"><img src="https://img.shields.io/badge/version-0.11.1-blue.svg" alt="Release Version"></a> <a href="https://godoc.org/aahframework.org/ahttp.v0"><img src="https://godoc.org/aahframework.org/ahttp.v0?status.svg" alt="Godoc"></a> <a href="https://twitter.com/aahframework"><img src="https://img.shields.io/badge/twitter-@aahframework-55acee.svg" alt="Twitter @aahframework"></a></p>
<p align="center"><a href="https://travis-ci.org/go-aah/ahttp"><img src="https://travis-ci.org/go-aah/ahttp.svg?branch=master" alt="Build Status"></a> <a href="https://codecov.io/gh/go-aah/ahttp/branch/master"><img src="https://codecov.io/gh/go-aah/ahttp/branch/master/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/aahframework.org/ahttp.v0"><img src="https://goreportcard.com/badge/aahframework.org/ahttp.v0" alt="Go Report Card"></a> <a href="https://github.com/go-aah/ahttp/releases/latest"><img src="https://img.shields.io/badge/version-0.11.2-blue.svg" alt="Release Version"></a> <a href="https://godoc.org/aahframework.org/ahttp.v0"><img src="https://godoc.org/aahframework.org/ahttp.v0?status.svg" alt="Godoc"></a> <a href="https://twitter.com/aahframework"><img src="https://img.shields.io/badge/twitter-@aahframework-55acee.svg" alt="Twitter @aahframework"></a></p>
</p>

HTTP extension Library is used to handle/process Request and Response (headers, body, gzip, etc).

### News

* `v0.11.1` [released](https://github.com/go-aah/ahttp/releases/latest) and tagged on Jul 22, 2018.
* `v0.11.2` [released](https://github.com/go-aah/ahttp/releases/latest) and tagged on Jul 27, 2018.

## Installation

Expand Down
7 changes: 4 additions & 3 deletions ahttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,20 @@ func WrapGzipWriter(w io.Writer) ResponseWriter {
//
// - returns `http`
func Scheme(r *http.Request) string {
if scheme := r.Header.Get(HeaderXForwardedProto); scheme != "" {
var scheme string
if scheme = r.Header.Get(HeaderXForwardedProto); len(scheme) > 0 {
return scheme
}

if scheme := r.Header.Get(HeaderXForwardedProtocol); scheme != "" {
if scheme = r.Header.Get(HeaderXForwardedProtocol); len(scheme) > 0 {
return scheme
}

if r.TLS != nil || r.Header.Get(HeaderXForwardedSsl) == "on" {
return "https"
}

if scheme := r.Header.Get(HeaderXUrlScheme); scheme != "" {
if scheme = r.Header.Get(HeaderXUrlScheme); len(scheme) > 0 {
return scheme
}

Expand Down
17 changes: 11 additions & 6 deletions content_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (
// ContentType is represents request and response content type values
type ContentType struct {
Mime string
raw string
Exts []string
Params map[string]string
}
Expand Down Expand Up @@ -115,14 +116,18 @@ func (c *ContentType) GetParam(key string) string {
// Raw method returns complete Content-Type composed.
// E.g.: application/json; charset=utf-8; version=2
func (c *ContentType) Raw() string {
raw := c.Mime
for k, v := range c.Params {
raw += fmt.Sprintf("; %s=%s", k, v)
}
return raw
return c.raw
}

// String is stringer interface
func (c ContentType) String() string {
return c.Raw()
return c.raw
}

func newContentType(ctype string, exts []string, params map[string]string) *ContentType {
raw := ctype
for k, v := range params {
raw += fmt.Sprintf("; %s=%s", k, v)
}
return &ContentType{Mime: ctype, Exts: exts, Params: params, raw: raw}
}
14 changes: 2 additions & 12 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ func NegotiateContentType(req *http.Request) *ContentType {
}

exts, _ := mime.ExtensionsByType(spec.Value)

return &ContentType{
Mime: spec.Value,
Exts: exts,
Params: spec.Params,
}
return newContentType(spec.Value, exts, spec.Params)
}

// NegotiateLocale method negotiates the `Accept-Language` from the given HTTP
Expand Down Expand Up @@ -340,10 +335,5 @@ func parseMediaType(value string) *ContentType {
}

exts, _ := mime.ExtensionsByType(ctype)

return &ContentType{
Mime: ctype,
Exts: exts,
Params: params,
}
return newContentType(ctype, exts, params)
}
6 changes: 3 additions & 3 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ func (p PathParams) Len() int {

func getReferer(hdr http.Header) string {
referer := hdr.Get(HeaderReferer)
if referer == "" {
return hdr.Get("Referrer")
if len(referer) > 0 {
return referer
}
return referer
return hdr.Get("Referrer")
}

func saveFile(r io.Reader, destFile string) (int64, error) {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
package ahttp

// Version no. of aah framework ahttp library
const Version = "0.11.1"
const Version = "0.11.2"

0 comments on commit 266c519

Please sign in to comment.