This commit is contained in:
Gerasimos (Makis) Maropoulos 2020-09-14 01:09:51 +03:00
parent fd5a2a7c58
commit 7113165cb8
No known key found for this signature in database
GPG Key ID: 5DBE766BD26A54E7
3 changed files with 34 additions and 11 deletions

View File

@ -805,9 +805,9 @@ type Configuration struct {
// //
// Defaults to an empty slice but an example usage is: // Defaults to an empty slice but an example usage is:
// RemoteAddrHeaders { // RemoteAddrHeaders {
// "X-Real-Ip", // "X-Real-Ip",
// "X-Forwarded-For", // "X-Forwarded-For",
// "CF-Connecting-IP", // "CF-Connecting-IP",
// } // }
// //
// Look `context.RemoteAddr()` for more. // Look `context.RemoteAddr()` for more.

View File

@ -125,9 +125,14 @@ func (s *Struct) Acquire(ctx *context.Context) (reflect.Value, error) {
continue continue
} }
// return emptyValue, err s.Container.GetErrorHandler(ctx).HandleError(ctx, err)
return ctrl, err
if ctx.IsStopped() {
// return emptyValue, err
return ctrl, err
} // #1629
} }
elem.FieldByIndex(b.Input.StructFieldIndex).Set(input) elem.FieldByIndex(b.Input.StructFieldIndex).Set(input)
} }
} }

View File

@ -713,14 +713,16 @@ func TestErrorHandlerContinue(t *testing.T) {
app := iris.New() app := iris.New()
m := New(app) m := New(app)
m.Handle(new(testControllerErrorHandlerContinue)) m.Handle(new(testControllerErrorHandlerContinue))
m.Handle(new(testControllerFieldErrorHandlerContinue))
e := httptest.New(t, app) e := httptest.New(t, app)
e.POST("/test").WithMultipart(). for _, path := range []string{"/test", "/test/field"} {
WithFormField("username", "makis"). e.POST(path).WithMultipart().
WithFormField("age", "27"). WithFormField("username", "makis").
WithFormField("unknown", "continue"). WithFormField("age", "27").
Expect().Status(httptest.StatusOK).Body().Equal("makis is 27 years old\n") WithFormField("unknown", "continue").
Expect().Status(httptest.StatusOK).Body().Equal("makis is 27 years old\n")
}
} }
type testControllerErrorHandlerContinue struct{} type testControllerErrorHandlerContinue struct{}
@ -741,3 +743,19 @@ func (c *testControllerErrorHandlerContinue) HandleError(ctx iris.Context, err e
func (c *testControllerErrorHandlerContinue) PostTest(form registerForm) string { func (c *testControllerErrorHandlerContinue) PostTest(form registerForm) string {
return fmt.Sprintf("%s is %d years old\n", form.Username, form.Age) return fmt.Sprintf("%s is %d years old\n", form.Username, form.Age)
} }
type testControllerFieldErrorHandlerContinue struct {
Form *registerForm
}
func (c *testControllerFieldErrorHandlerContinue) HandleError(ctx iris.Context, err error) {
if iris.IsErrPath(err) {
return // continue.
}
ctx.StopWithError(iris.StatusBadRequest, err)
}
func (c *testControllerFieldErrorHandlerContinue) PostTestField() string {
return fmt.Sprintf("%s is %d years old\n", c.Form.Username, c.Form.Age)
}