1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-23 21:24:02 +00:00
This commit is contained in:
Fenny 2020-04-28 21:29:20 +02:00
parent e5e887f9e0
commit 2267f8790c
7 changed files with 11 additions and 11 deletions

2
.github/.gitpod.yml vendored
View File

@ -1,2 +0,0 @@
tasks:
- init: go get && go build ./... && go test ./...

1
.github/CNAME vendored
View File

@ -1 +0,0 @@
fiber.wiki

3
app.go
View File

@ -48,7 +48,8 @@ type Settings struct {
ServerHeader string // default: "" ServerHeader string // default: ""
// Enables handler values to be immutable even if you return from handler // Enables handler values to be immutable even if you return from handler
Immutable bool // default: false Immutable bool // default: false
// Enable or disable ETag header generation // Enable or disable ETag header generation, since both weak and strong etags are generated
// using the same hashing method (CRC-32). Weak ETags are the default when enabled.
// Optional. Default value false // Optional. Default value false
ETag bool ETag bool
// Max body size that the server accepts // Max body size that the server accepts

View File

@ -96,7 +96,7 @@ func Test_Static(t *testing.T) {
DisableStartupMessage: true, DisableStartupMessage: true,
}) })
grp := app.Group("/v1") grp := app.Group("/v1")
grp.Static("/v2", ".travis.yml") grp.Static("/v2", ".github/auth_assign.yml")
app.Static("/*", ".github/FUNDING.yml") app.Static("/*", ".github/FUNDING.yml")
app.Static("/john", "./.github") app.Static("/john", "./.github")
req, _ := http.NewRequest("GET", "/john/stale.yml", nil) req, _ := http.NewRequest("GET", "/john/stale.yml", nil)

6
ctx.go
View File

@ -409,7 +409,11 @@ func (ctx *Ctx) FormValue(key string) (value string) {
return getString(ctx.Fasthttp.FormValue(key)) return getString(ctx.Fasthttp.FormValue(key))
} }
// Fresh is not implemented yet, pull requests are welcome! // Fresh When the response is still “fresh” in the clients cache true is returned,
// otherwise false is returned to indicate that the client cache is now stale
// and the full response should be sent.
// When a client sends the Cache-Control: no-cache request header to indicate an end-to-end
// reload request, this module will return false to make handling these requests transparent.
// https://github.com/jshttp/fresh/blob/10e0471669dbbfbfd8de65bc6efac2ddd0bfa057/index.js#L33 // https://github.com/jshttp/fresh/blob/10e0471669dbbfbfd8de65bc6efac2ddd0bfa057/index.js#L33
func (ctx *Ctx) Fresh() bool { func (ctx *Ctx) Fresh() bool {
// fields // fields

View File

@ -44,7 +44,7 @@ func (app *App) nextRoute(ctx *Ctx) {
route.Handler(ctx) route.Handler(ctx)
// Generate ETag if enabled / found // Generate ETag if enabled / found
if app.Settings.ETag { if app.Settings.ETag {
getETag(ctx, ctx.Fasthttp.Response.Body(), false) setETag(ctx, ctx.Fasthttp.Response.Body(), false)
} }
return return
} }
@ -266,13 +266,11 @@ func (app *App) registerStatic(prefix, root string, config ...Static) {
} }
// Serve file // Serve file
fileHandler(c.Fasthttp) fileHandler(c.Fasthttp)
// End response when file is found // End response when file is found
if c.Fasthttp.Response.StatusCode() != 404 { if c.Fasthttp.Response.StatusCode() != 404 {
return return
} }
// Reset response // Reset response
//c.Fasthttp.ResetBody() // Dit is iets anders
c.Fasthttp.Response.Reset() c.Fasthttp.Response.Reset()
} }
c.Next() c.Next()

View File

@ -18,7 +18,7 @@ import (
) )
// Document elke line gelijk even // Document elke line gelijk even
func getETag(ctx *Ctx, body []byte, weak bool) { func setETag(ctx *Ctx, body []byte, weak bool) {
// Skips ETag if no response body is present // Skips ETag if no response body is present
if len(body) <= 0 { if len(body) <= 0 {
return return
@ -32,7 +32,7 @@ func getETag(ctx *Ctx, body []byte, weak bool) {
// Enable weak tag // Enable weak tag
if weak { if weak {
etag = "W/" + etag etag = "W/" + "\"" + etag + "\""
} }
// Check if client's ETag is weak // Check if client's ETag is weak