-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Can add the StaticCustomWithFilters function? #33
Comments
Yes, the static files hasn't middlewares and filters. I will add it in a few days. |
I've just added Now static files will process the global middlewares and allow filters ;) |
Thanks!
This method of RequestHandlerPathWithFilters is very useful. Can use this method to achieve upload
|
I recommend you to use |
See this example: https://github.com/savsgio/atreugo/tree/master/examples/static_files |
avoid extra allocation, increasing performance But in the StaticCustom method, the Path is: My understanding should be the same, Where is the difference? |
I have already seen https://github.com/savsgio/atreugo/tree/master/examples/static_files |
Here, you are creating a new FS (extra allocations, it's better preallocating before and use the request handler of FS) on every requests: func staticFile(ctx *fasthttp.RequestCtx) {
ctx.Response.Header.SetCanonical([]byte("Cache-Control"), []byte("public, max-age=3600"))
fs := &fasthttp.FS{
Root: "/static",
IndexNames: []string{"index.html"},
GenerateIndexPages: false,
Compress: true,
AcceptByteRange: false,
PathNotFound: noFile,
}
fsHandler := fs.NewRequestHandler()
fsHandler(ctx)
} You should move this two lines outside. fs := &fasthttp.FS{
Root: "/static",
IndexNames: []string{"index.html"},
GenerateIndexPages: false,
Compress: true,
AcceptByteRange: false,
PathNotFound: noFile,
}
fsHandler := fs.NewRequestHandler() In Something like this: fs := &fasthttp.FS{
Root: "/static",
IndexNames: []string{"index.html"},
GenerateIndexPages: false,
Compress: true,
AcceptByteRange: false,
PathNotFound: noFile,
}
fsHandler := fs.NewRequestHandler()
func staticFile(ctx *fasthttp.RequestCtx) {
ctx.Response.Header.SetCanonical([]byte("Cache-Control"), []byte("public, max-age=3600"))
fsHandler(ctx)
} |
In Atreugo filters := atreugo.Filters{
After: []atreugo.Middleware{func(ctx *atreugo.RequestCtx) (int, error) {
ctx.Response.Header.SetCanonical([]byte("Cache-Control"), []byte("public, max-age=3600"))
return 200, nil
}},
}
server.StaticCustom("/mypath", &StaticFS{
Filters: filters,
Root: "/static",
IndexNames: []string{"index.html"},
GenerateIndexPages: false,
Compress: true,
AcceptByteRange: false,
PathNotFound: noFile,
}) |
I understand, I made a mistake that should not be made. |
Please forgive my request because the project(static file server) needs ip whitelist and add Cache-Control header.
Atreugo's static file functions are not middlewares and filter.
I am going to write a StaticCustom function with filter, but find i can't use the router.ServeFilesCustom().
The text was updated successfully, but these errors were encountered: