-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
Description
Bug Description
Unix domain socket gives an Internal Server Error using adaptor middleware
How to Reproduce
Steps to reproduce the behavior:
- Run the following code snippet (attached)
- Curl the endpoint
curl --unix-socket /tmp/test.sock http://localhost/hello - Response: Internal Server Error
Expected Behavior
{"message":"Hello from Fiber with http.Server!"}%
Fiber Version
v2.52.9
Code Snippet (optional)
package main
import (
"log"
"net"
"net/http"
"os"
"syscall"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/adaptor"
)
var socketPath = "/tmp/test.sock"
func main() {
app := fiber.New(fiber.Config{})
app.Get("/hello", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"message": "Hello from Fiber with http.Server!",
})
})
if _, err := os.Stat(socketPath); !os.IsNotExist(err) {
if err = syscall.Unlink(socketPath); err != nil {
log.Fatalf("socket remove error: %s\n", err.Error())
}
}
listener, err := net.Listen("unix", socketPath)
if err != nil {
log.Fatal(err.Error())
}
// Create an http.Handler from Fiber
handler := adaptor.FiberApp(app)
if err := http.Serve(listener, handler); err != nil {
log.Fatalf("error serving on unix socket: %v", err)
}
// log.Fatal(app.Listener(listener)) - this works
}Checklist:
- I agree to follow Fiber's Code of Conduct.
- I have checked for existing issues that describe my problem prior to opening this one.
- I understand that improperly formatted bug reports may be closed without explanation.
Reactions are currently unavailable