-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ajust config.Next position #1135
Conversation
middleware/cache/cache_test.go
Outdated
}) | ||
|
||
app.Get("/error", func(c *fiber.Ctx) error { | ||
return c.Status(fiber.StatusInternalServerError).Send([]byte(time.Now().String())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you use Send here but not SendString?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I will change that.
middleware/cache/cache_test.go
Outdated
body, err := ioutil.ReadAll(resp.Body) | ||
utils.AssertEqual(t, nil, err) | ||
|
||
time.Sleep(500 * time.Millisecond) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the meaning of Sleep here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the begining, I just want to make sure to return different string. Now I found it doesn't need to do that. I will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can take advantage of CacheControl option? If it is true, we'll get extra response header if it's cached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add a new commit, plz have a look.
middleware/cache/cache_test.go
Outdated
body, err = ioutil.ReadAll(resp.Body) | ||
utils.AssertEqual(t, nil, err) | ||
|
||
time.Sleep(500 * time.Millisecond) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
middleware/cache/cache_test.go
Outdated
|
||
app.Use(New(Config{ | ||
Next: func(c *fiber.Ctx) bool { | ||
if c.Response().StatusCode() == fiber.StatusOK { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please simplify these code 😃
05b8f52
to
daf5749
Compare
Please check error in CI |
Will the Custom Config readme example still be relevant with this change? https://github.com/gofiber/fiber/tree/master/middleware/cache#custom-config |
@kiyonlin I check the errorr, but it seems like proxy middleware test cases have data race: |
Re-running tests |
@kiyonlin I have removed body check, plz have a look. |
Please provide enough information so that others can review your pull request:
The intention of this PR is to address the issue raised here: 1116
Explain the details for making this change. What existing problem does the pull request solve?
Move
config.Next
afterctx.Next
, so we can determine whether to cache or not after handling biz logic.Use emojis on commit messages so it provides an easy way of identifying the purpose or intention of a commit. Check out the emoji cheatsheet here: https://gitmoji.carloscuesta.me/