Skip to content

Commit

Permalink
Merge pull request #202 for v0.11.1 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Jul 22, 2018
2 parents 3a30b0c + c8d9a4f commit f7bf268
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 129 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<p align="center">Visit aah's official website https://aahframework.org to learn more</p>
</p>
<p align="center">
<p align="center"><a href="https://travis-ci.org/go-aah/aah"><img src="https://travis-ci.org/go-aah/aah.svg?branch=master" alt="Build Status"></a> <a href="https://codecov.io/gh/go-aah/aah/branch/master"><img src="https://codecov.io/gh/go-aah/aah/branch/master/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/aahframework.org/aah.v0"><img src="https://goreportcard.com/badge/aahframework.org/aah.v0" alt="Go Report Card"></a> <a href="https://github.com/go-aah/aah/releases/latest"><img src="https://img.shields.io/badge/version-0.11.0-blue.svg" alt="Release Version"></a> <a href="https://godoc.org/aahframework.org/aah.v0"><img src="https://godoc.org/aahframework.org/aah.v0?status.svg" alt="Godoc"></a> <a href="https://hub.docker.com/r/aahframework/aah/"><img src="https://img.shields.io/docker/pulls/aahframework/aah.svg" alt="Docker Pulls"></a> <a href="https://twitter.com/aahframework"><img src="https://img.shields.io/badge/[email protected]" alt="Twitter @aahframework"></a></p>
<p align="center"><a href="https://travis-ci.org/go-aah/aah"><img src="https://travis-ci.org/go-aah/aah.svg?branch=master" alt="Build Status"></a> <a href="https://codecov.io/gh/go-aah/aah/branch/master"><img src="https://codecov.io/gh/go-aah/aah/branch/master/graph/badge.svg" alt="Code Coverage"></a> <a href="https://goreportcard.com/report/aahframework.org/aah.v0"><img src="https://goreportcard.com/badge/aahframework.org/aah.v0" alt="Go Report Card"></a> <a href="https://github.com/go-aah/aah/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/aah.v0"><img src="https://godoc.org/aahframework.org/aah.v0?status.svg" alt="Godoc"></a> <a href="https://hub.docker.com/r/aahframework/aah/"><img src="https://img.shields.io/docker/pulls/aahframework/aah.svg" alt="Docker Pulls"></a> <a href="https://twitter.com/aahframework"><img src="https://img.shields.io/badge/[email protected]" alt="Twitter @aahframework"></a></p>
</p>

### News

* `v0.11.0` [released](https://docs.aahframework.org/release-notes.html) and tagged on Jul 06, 2018.
* `v0.11.1` [released](https://docs.aahframework.org/release-notes.html) and tagged on Jul 22, 2018.

### Stargazers over time

Expand Down
15 changes: 6 additions & 9 deletions aah.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ type BuildInfo struct {
func newApp() *app {
aahApp := &app{
vfs: new(vfs.VFS),
mu: new(sync.Mutex),
}

aahApp.he = &HTTPEngine{
Expand All @@ -70,7 +69,7 @@ func newApp() *app {
aahApp.eventStore = &EventStore{
a: aahApp,
subscribers: make(map[string]EventCallbacks),
mu: new(sync.Mutex),
mu: sync.RWMutex{},
}

return aahApp
Expand All @@ -90,6 +89,7 @@ type app struct {
initialized bool
hotReload bool
authSchemeExists bool
redirect bool
pid int
httpMaxHdrBytes int
importPath string
Expand Down Expand Up @@ -128,8 +128,6 @@ type app struct {
logger log.Loggerer
accessLog *accessLogger
dumpLog *dumpLogger

mu *sync.Mutex
}

func (a *app) Init(importPath string) error {
Expand Down Expand Up @@ -283,8 +281,6 @@ func (a *app) Profile() string {
}

func (a *app) SetProfile(profile string) error {
a.mu.Lock()
defer a.mu.Unlock()
if err := a.Config().SetProfile(profilePrefix + profile); err != nil {
return err
}
Expand Down Expand Up @@ -335,8 +331,6 @@ func (a *app) NewChildLogger(fields log.Fields) log.Loggerer {
}

func (a *app) SetTLSConfig(tlsCfg *tls.Config) {
a.mu.Lock()
defer a.mu.Unlock()
a.tlsCfg = tlsCfg
}

Expand Down Expand Up @@ -434,6 +428,8 @@ func (a *app) initConfigValues() (err error) {
return err
}

a.redirect = cfg.BoolDefault("server.redirect.enable", false)

readTimeout := cfg.StringDefault("server.timeout.read", "90s")
writeTimeout := cfg.StringDefault("server.timeout.write", "90s")
if !isValidTimeUnit(readTimeout, "s", "m") || !isValidTimeUnit(writeTimeout, "s", "m") {
Expand Down Expand Up @@ -589,7 +585,8 @@ func (a *app) aahRecover() {
// ServeHTTP method implementation of http.Handler interface.
func (a *app) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer a.aahRecover()
if a.he.doRedirect(w, r) {
if a.redirect {
a.he.doRedirect(w, r)
return
}

Expand Down
2 changes: 1 addition & 1 deletion access_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (al *accessLog) GetResponseHdr(hdrKey string) string {

func (al *accessLog) GetQueryString() string {
queryStr := al.Request.URL().Query().Encode()
if ess.IsStrEmpty(queryStr) {
if len(queryStr) == 0 {
return "-"
}
return `"` + queryStr + `"`
Expand Down
2 changes: 1 addition & 1 deletion bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func BindMiddleware(ctx *Context, m *Middleware) {
// Note: Query parameter takes precedence of all.
if locale := firstNonZeroString(
ctx.Req.QueryValue(ctx.a.bindMgr.keyQueryParamName),
ctx.Req.PathValue(ctx.a.bindMgr.keyPathParamName)); !ess.IsStrEmpty(locale) {
ctx.Req.PathValue(ctx.a.bindMgr.keyPathParamName)); len(locale) > 0 {
ctx.Req.SetLocale(ahttp.NewLocale(locale))
}
}
Expand Down
2 changes: 1 addition & 1 deletion dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (d *dumpLogger) Dump(ctx *Context) {

// Request
uri := fmt.Sprintf("%s://%s%s", ctx.Req.Scheme, ctx.Req.Host, ctx.Req.Path)
if qs := ctx.Req.URL().RawQuery; !ess.IsStrEmpty(qs) {
if qs := ctx.Req.URL().RawQuery; len(qs) > 0 {
uri += "?" + qs
}

Expand Down
3 changes: 1 addition & 2 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net/http"

"aahframework.org/ahttp.v0"
"aahframework.org/essentials.v0"
)

// aah errors
Expand Down Expand Up @@ -161,7 +160,7 @@ func (er *errorManager) Handle(ctx *Context) {
// in the aah. It writes the response based on HTTP Content-Type.
func (er *errorManager) DefaultHandler(ctx *Context, err *Error) bool {
ct := ctx.Reply().ContType
if ess.IsStrEmpty(ct) {
if len(ct) == 0 {
ct = ctx.detectContentType().Mime
if ctx.a.viewMgr == nil && ct == ahttp.ContentTypeHTML.Mime {
ct = ahttp.ContentTypePlainText.Mime
Expand Down
2 changes: 1 addition & 1 deletion event.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (a *app) EventStore() *EventStore {
// EventStore type holds all the events belongs to aah application.
type EventStore struct {
a *app
mu *sync.Mutex
mu sync.RWMutex
subscribers map[string]EventCallbacks
}

Expand Down
19 changes: 5 additions & 14 deletions http_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"aahframework.org/ahttp.v0"
"aahframework.org/ainsp.v0"
"aahframework.org/aruntime.v0"
"aahframework.org/essentials.v0"
"aahframework.org/log.v0"
"aahframework.org/security.v0"
"aahframework.org/security.v0/authc"
Expand Down Expand Up @@ -73,14 +72,14 @@ func (e *HTTPEngine) Handle(w http.ResponseWriter, r *http.Request) {
ctx := e.ctxPool.Get().(*Context)
defer e.releaseContext(ctx)

ctx.Req, ctx.Res = ahttp.AcquireRequest(r), ahttp.AcquireResponseWriter(w)
ctx.Set(reqStartTimeKey, time.Now())

// Record access log
if e.a.accessLogEnabled {
ctx.Set(reqStartTimeKey, time.Now())
defer e.a.accessLog.Log(ctx)
}

ctx.Req, ctx.Res = ahttp.AcquireRequest(r), ahttp.AcquireResponseWriter(w)

// Recovery handling
defer e.handleRecovery(ctx)

Expand Down Expand Up @@ -319,7 +318,7 @@ func (e *HTTPEngine) writeReply(ctx *Context) {
}

// Check ContentType and detect it if need be
if ess.IsStrEmpty(re.ContType) {
if len(re.ContType) == 0 {
re.ContentType(ctx.detectContentType().String())
}
ctx.Res.Header().Set(ahttp.HeaderContentType, re.ContType)
Expand Down Expand Up @@ -433,12 +432,8 @@ const (
nonwww = "non-www"
)

func (e *HTTPEngine) doRedirect(w http.ResponseWriter, r *http.Request) bool {
func (e *HTTPEngine) doRedirect(w http.ResponseWriter, r *http.Request) {
cfg := e.a.Config()
if !cfg.BoolDefault("server.redirect.enable", false) {
return false
}

redirectTo := cfg.StringDefault("server.redirect.to", nonwww)
redirectCode := cfg.IntDefault("server.redirect.code", http.StatusMovedPermanently)
host := ahttp.Host(r)
Expand All @@ -447,14 +442,10 @@ func (e *HTTPEngine) doRedirect(w http.ResponseWriter, r *http.Request) bool {
case www:
if host[:3] != www {
http.Redirect(w, r, ahttp.Scheme(r)+"://www."+host+r.URL.RequestURI(), redirectCode)
return true
}
case nonwww:
if host[:3] == www {
http.Redirect(w, r, ahttp.Scheme(r)+"://"+host[4:]+r.URL.RequestURI(), redirectCode)
return true
}
}

return false
}
87 changes: 38 additions & 49 deletions http_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestHTTPEngineTestRequests(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, "application/json; charset=utf-8", resp.Header.Get(ahttp.HeaderContentType))
assert.Equal(t, "134", resp.Header.Get(ahttp.HeaderContentLength))
assert.Equal(t, "135", resp.Header.Get(ahttp.HeaderContentLength))
assert.True(t, strings.HasPrefix(responseBody(resp), `)]}',`))

// GET Binary bytes - /binary-bytes
Expand Down Expand Up @@ -221,7 +221,6 @@ func TestHTTPEngineTestRequests(t *testing.T) {
func TestServerRedirect(t *testing.T) {
a := newApp()
a.cfg = config.NewEmpty()
a.he.doRedirect(nil, nil)

// www redirect
t.Log("www redirect")
Expand All @@ -236,20 +235,18 @@ func TestServerRedirect(t *testing.T) {
`)

type redirectTestCase struct {
label string
fromURL string
didItHappen bool
status int
location string
label string
fromURL string
status int
location string
}

runtestcase := func(testcases []redirectTestCase) {
for _, tc := range testcases {
t.Run(tc.label, func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(ahttp.MethodGet, tc.fromURL, nil)
didItHappen := a.he.doRedirect(w, r)
assert.Equal(t, tc.didItHappen, didItHappen)
a.he.doRedirect(w, r)
assert.Equal(t, tc.status, w.Code)
assert.Equal(t, tc.location, w.Header().Get(ahttp.HeaderLocation))
})
Expand All @@ -258,32 +255,28 @@ func TestServerRedirect(t *testing.T) {

testcases := []redirectTestCase{
{
label: "www domain",
fromURL: "http://aahframework.org/home.html?rt=login",
didItHappen: true,
status: http.StatusTemporaryRedirect,
location: "http://www.aahframework.org/home.html?rt=login",
label: "www domain",
fromURL: "http://aahframework.org/home.html?rt=login",
status: http.StatusTemporaryRedirect,
location: "http://www.aahframework.org/home.html?rt=login",
},
{
label: "www subdomain",
fromURL: "http://docs.aahframework.org",
didItHappen: true,
status: http.StatusTemporaryRedirect,
location: "http://www.docs.aahframework.org/",
label: "www subdomain",
fromURL: "http://docs.aahframework.org",
status: http.StatusTemporaryRedirect,
location: "http://www.docs.aahframework.org/",
},
{
label: "www domain already correct",
fromURL: "http://www.aahframework.org",
didItHappen: false,
status: http.StatusOK,
location: "",
label: "www domain already correct",
fromURL: "http://www.aahframework.org",
status: http.StatusOK,
location: "",
},
{
label: "www subdomain already correct",
fromURL: "http://www.docs.aahframework.org",
didItHappen: false,
status: http.StatusOK,
location: "",
label: "www subdomain already correct",
fromURL: "http://www.docs.aahframework.org",
status: http.StatusOK,
location: "",
},
}

Expand All @@ -301,32 +294,28 @@ func TestServerRedirect(t *testing.T) {

testcases = []redirectTestCase{
{
label: "non-www domain",
fromURL: "http://www.aahframework.org/home.html?rt=login",
didItHappen: true,
status: http.StatusMovedPermanently,
location: "http://aahframework.org/home.html?rt=login",
label: "non-www domain",
fromURL: "http://www.aahframework.org/home.html?rt=login",
status: http.StatusMovedPermanently,
location: "http://aahframework.org/home.html?rt=login",
},
{
label: "non-www subdomain",
fromURL: "http://www.docs.aahframework.org",
didItHappen: true,
status: http.StatusMovedPermanently,
location: "http://docs.aahframework.org/",
label: "non-www subdomain",
fromURL: "http://www.docs.aahframework.org",
status: http.StatusMovedPermanently,
location: "http://docs.aahframework.org/",
},
{
label: "non-www domain already correct",
fromURL: "http://aahframework.org",
didItHappen: false,
status: http.StatusOK,
location: "",
label: "non-www domain already correct",
fromURL: "http://aahframework.org",
status: http.StatusOK,
location: "",
},
{
label: "non-www subdomain already correct",
fromURL: "http://docs.aahframework.org",
didItHappen: false,
status: http.StatusOK,
location: "",
label: "non-www subdomain already correct",
fromURL: "http://docs.aahframework.org",
status: http.StatusOK,
location: "",
},
}

Expand Down
Loading

0 comments on commit f7bf268

Please sign in to comment.