This commit is contained in:
Gerasimos (Makis) Maropoulos 2016-12-22 19:07:03 +02:00
parent 1f25e4335a
commit fe79fdea44
4 changed files with 32 additions and 8 deletions

View File

@ -97,7 +97,7 @@ type (
Middleware Middleware // exported because is useful for debugging
session sessions.Session
// Pos is the position number of the Context, look .Next to understand
Pos uint8 // exported because is useful for debugging
Pos int // exported because is useful for debugging
}
)
@ -116,7 +116,7 @@ func (ctx *Context) Do() {
func (ctx *Context) Next() {
//set position to the next
ctx.Pos++
midLen := uint8(len(ctx.Middleware))
midLen := len(ctx.Middleware)
//run the next
if ctx.Pos < midLen {
ctx.Middleware[ctx.Pos].Serve(ctx)
@ -1365,6 +1365,13 @@ func (ctx *Context) BeginTransaction(pipe func(scope *TransactionScope)) {
// and replaces the context's response with an error.
// if the transaction completed successfully then we need to pass the temp's context's response to this context.
// so we must copy back its context at all cases, no matter the result of the transaction.
// TODO: GREEK, THESE COMMENTS WILL BE REMOVED AFTER I FIX A RECENT BUG REPORTED BY COMMUNITY
// auto to xreiazomaste gia na pianei ta errors kiolas, ara prepei na vrw allous tropous
// na manteuw an 9elei o xristis na dixnei errors sto transaction h apla na to kanei skip
// alla tautoxrona ena failed transaction sto telos na mh kanei reset ta proigoumena, gt twra auto kanei,
// kai auto xreiazete omws se arketes periptwseis alla prepei kiolas na diaxwrizw to ka9e transaction na einai aneksartita
// pisteuw to Response.Reset dn 9a mas xreiastei ka9olou, prepei na ktlvenw mono pote xreiazete na kanw copy to scope's context kai pote oxi.
*ctx = *scope.Context
// if the scope had lifetime of the whole request and it completed with an error(failure)

View File

@ -5,15 +5,16 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"github.com/gavv/httpexpect"
"github.com/kataras/iris"
"github.com/kataras/iris/httptest"
"github.com/valyala/fasthttp"
"net/url"
"strconv"
"strings"
"testing"
"time"
"github.com/gavv/httpexpect"
"github.com/kataras/iris"
"github.com/kataras/iris/httptest"
"github.com/valyala/fasthttp"
)
// White-box testing *
@ -849,6 +850,14 @@ func TestTransactions(t *testing.T) {
ctx.BeginTransaction(successTransaction)
})
/*TODO: MAKE THIS TO WORK
iris.Get("/failFirsAndThirdTransactionsButSuccessSecond", func(ctx *iris.Context) {
ctx.BeginTransaction(maybeFailureTransaction(true, false))
ctx.BeginTransaction(successTransaction)
ctx.BeginTransaction(maybeFailureTransaction(true, false))
})
*/
iris.Get("/failAllBecauseOfRequestScopeAndFailure", func(ctx *iris.Context) {
ctx.BeginTransaction(maybeFailureTransaction(true, true))
ctx.BeginTransaction(successTransaction)
@ -869,6 +878,14 @@ func TestTransactions(t *testing.T) {
ContentType("text/html", iris.Config.Charset).
Body().
Equal(firstTransactionFailureMessage + secondTransactionSuccessHTMLMessage)
/*
e.GET("/failFirsAndThirdTransactionsButSuccessSecond").
Expect().
Status(iris.StatusOK).
ContentType("text/html", iris.Config.Charset).
Body().
Equal(firstTransactionFailureMessage + secondTransactionSuccessHTMLMessage)
*/
e.GET("/failAllBecauseOfRequestScopeAndFailure").
Expect().

View File

@ -948,7 +948,7 @@ func (mux *serveMux) fireError(statusCode int, ctx *Context) {
errHandler := mux.errorHandlers[statusCode]
if errHandler == nil {
errHandler = HandlerFunc(func(ctx *Context) {
ctx.ResetBody()
ctx.Response.Reset()
ctx.SetStatusCode(statusCode)
ctx.SetBodyString(statusText[statusCode])
})

View File

@ -1772,7 +1772,7 @@ func (api *muxAPI) StaticHandler(systemPath string, stripSlashes int, compress b
if errCode == StatusNotFound || errCode == StatusBadRequest || errCode == StatusInternalServerError {
api.mux.fireError(errCode, ctx)
}
if ctx.Pos < uint8(len(ctx.Middleware))-1 {
if ctx.Pos < len(ctx.Middleware)-1 {
ctx.Next() // for any case
}