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

✨ add Next function to app.Static config #1130

Merged
merged 3 commits into from Jan 31, 2021
Merged

✨ add Next function to app.Static config #1130

merged 3 commits into from Jan 31, 2021

Conversation

mlukasik-dev
Copy link
Contributor

Please provide enough information so that others can review your pull request:

I've added option to to skip app.Static middleware. Mechanism is identical with proxy.Config.Next function from proxy middleware.

Explain the details for making this change. What existing problem does the pull request solve?

This can be feature is crucial for example when you want to serve different static files based on whether the user is authenticated.
Or when you just want to protect static file from unauthenticated users.

Commit formatting

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/

@welcome
Copy link

welcome bot commented Jan 22, 2021

Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

Copy link
Contributor

@kiyonlin kiyonlin left a comment

Choose a reason for hiding this comment

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

Could you please add some test cases?

@mlukasik-dev
Copy link
Contributor Author

Could you please add some test cases?

Sure, and thanks for reply!)

Copy link
Contributor

@kiyonlin kiyonlin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@ReneWerner87 ReneWerner87 self-requested a review January 24, 2021 09:51
Copy link
Member

@ReneWerner87 ReneWerner87 left a comment

Choose a reason for hiding this comment

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

@mlukasik-dev
Could you add the new options also in the gofiber docs repository
https://github.com/gofiber/docs/blob/master/api/app.md

@mlukasik-dev
Copy link
Contributor Author

@ReneWerner87
I'll do that today.

// Next defines a function to skip this middleware when returned true.
//
// Optional. Default: nil
Next func(c *Ctx) bool
Copy link
Member

Choose a reason for hiding this comment

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

Could you change this to the Handler type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Assuming that you're talking about this Handler type:

// Handler defines a function to serve HTTP requests.
type Handler = func(*Ctx) error

I'm not sure under what circumstances the middleware should be skipped.
If Handler returns nil or error?

Here is current login of app.Static:

// Don't execute middleware if Next returns true
if config != nil && config[0].Next != nil && config[0].Next(c) {
    return c.Next()
}
// Serve file
// ...

@mlukasik-dev
Copy link
Contributor Author

@Fenny
So what's the status of this pull request?
Should I really change type to Handler

@Fenny
Copy link
Member

Fenny commented Jan 31, 2021

@mlukasik-dev totally missed the bool mb!

@Fenny Fenny merged commit e89ef12 into gofiber:master Jan 31, 2021
@welcome
Copy link

welcome bot commented Jan 31, 2021

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

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

Successfully merging this pull request may close these issues.

None yet

4 participants