| 899 | } |
| 900 | |
| 901 | func TestRouterOptionsMethodHandler(t *testing.T) { |
| 902 | e := New() |
| 903 | |
| 904 | var keyInContext any |
| 905 | e.Use(func(next HandlerFunc) HandlerFunc { |
| 906 | return func(c *Context) error { |
| 907 | err := next(c) |
| 908 | keyInContext = c.Get(ContextKeyHeaderAllow) |
| 909 | return err |
| 910 | } |
| 911 | }) |
| 912 | e.GET("/test", func(c *Context) error { |
| 913 | return c.String(http.StatusOK, "Echo!") |
| 914 | }) |
| 915 | |
| 916 | req := httptest.NewRequest(http.MethodOptions, "/test", nil) |
| 917 | rec := httptest.NewRecorder() |
| 918 | e.ServeHTTP(rec, req) |
| 919 | |
| 920 | assert.Equal(t, http.StatusNoContent, rec.Code) |
| 921 | assert.Equal(t, "OPTIONS, GET", rec.Header().Get(HeaderAllow)) |
| 922 | assert.Equal(t, "OPTIONS, GET", keyInContext) |
| 923 | } |
| 924 | |
| 925 | func TestRouterHandleMethodOptions(t *testing.T) { |
| 926 | e := New() |