Skip to content

static file always return 404 even if get the correct response body #68

@xy6321

Description

@xy6321

Let me simplify the code

package main

import (
	"net/http"
	"time"

	"github.com/gin-contrib/timeout"
	"github.com/gin-gonic/gin"
)

func timeoutMiddleware() gin.HandlerFunc {
	return timeout.New(
		timeout.WithTimeout(500*time.Millisecond),
		timeout.WithHandler(func(c *gin.Context) {
			c.Next()
		}),
		timeout.WithResponse(func(c *gin.Context) {
			c.String(http.StatusRequestTimeout, "timeout")
		}),
	)
}

func main() {
	gin.SetMode(gin.ReleaseMode)
	r := gin.New()

	r.Use(timeoutMiddleware())
	r.Static("/log", "./")
	r.Run(":8888")
}

When i try to get http://localhost:8888/log/go.sum
i can get correct file content in response body but http status code is 404
image

go version go1.21.5 linux/amd64

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions