Skip to content
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

Merged
merged 1 commit into from
Jan 31, 2021
Merged

ajust config.Next position #1135

merged 1 commit into from
Jan 31, 2021

Conversation

tianjipeng
Copy link
Contributor

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 after ctx.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/

})

app.Get("/error", func(c *fiber.Ctx) error {
return c.Status(fiber.StatusInternalServerError).Send([]byte(time.Now().String()))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

body, err := ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)

time.Sleep(500 * time.Millisecond)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

body, err = ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err)

time.Sleep(500 * time.Millisecond)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here


app.Use(New(Config{
Next: func(c *fiber.Ctx) bool {
if c.Response().StatusCode() == fiber.StatusOK {
Copy link
Contributor

@kiyonlin kiyonlin Jan 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please simplify these code 😃

@tianjipeng tianjipeng force-pushed the fix/cache branch 2 times, most recently from 05b8f52 to daf5749 Compare January 25, 2021 05:22
@kiyonlin
Copy link
Contributor

Please check error in CI

@l3uddz
Copy link

l3uddz commented Jan 25, 2021

Will the Custom Config readme example still be relevant with this change?

https://github.com/gofiber/fiber/tree/master/middleware/cache#custom-config

@tianjipeng
Copy link
Contributor Author

@kiyonlin I check the errorr, but it seems like proxy middleware test cases have data race:
image

@Fenny
Copy link
Member

Fenny commented Jan 25, 2021

Re-running tests

@tianjipeng
Copy link
Contributor Author

@Fenny @kiyonlin I check CI error and review the test code, I can't figure out why there is an error on windows platform. Could you have a look on my test case?

@kiyonlin
Copy link
Contributor

@Fenny @kiyonlin I check CI error and review the test code, I can't figure out why there is an error on windows platform. Could you have a look on my test case?

How about removing body check?

@tianjipeng
Copy link
Contributor Author

@kiyonlin I have removed body check, plz have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants