Giter Club home page Giter Club logo

gin-method-override's People

Contributors

bu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gin-method-override's Issues

It seems to run the request twice

When I added this, it works, but it seems to run the method twice according to the logs (and database) :)

I slightly modified from your example in README.md:

main.go:

package main

import (
	method "github.com/bu/gin-method-override"
	gin "github.com/gin-gonic/gin"
)

func main() {
	// create a Gin engine
	r := gin.Default()
	r.LoadHTMLFiles("form.html")

	// our middle-ware
	r.Use(method.ProcessMethodOverride(r))

	// routes
	r.PUT("/test", func(c *gin.Context) {
		c.String(200, "1")
	})
	r.GET("/", func(c *gin.Context) {
		c.HTML(200, "form.html", gin.H{})
	})

	// listen to request
	r.Run(":8080")
}

form.html: (same as example)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
    <form action="/test" method="POST"> <!-- form method rewrite only works with POST request -->
        <input type="hidden" name="_method" value="PUT">
        <input type="text" name="testing" value="1">
        <button type="submit">Send</button>
    </form>
</body>
</html>

The output is: 11 instead of the expected 1 and I also see the line twice in the logs:

$ go run main.go 
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] PUT    /test                     --> main.main.func1 (4 handlers)
[GIN-debug] GET    /                         --> main.main.func2 (4 handlers)
[GIN-debug] Listening and serving HTTP on :8080



[GIN] 2021/01/06 - 21:12:36 | 200 |     285.465µs |             ::1 | GET      "/"
[GIN] 2021/01/06 - 21:12:45 | 200 |       5.609µs |             ::1 | PUT      "/test"
[GIN] 2021/01/06 - 21:12:45 | 200 |      70.195µs |             ::1 | PUT      "/test"

Hide first request in logging

What is happening now?

Currently, this middleware will print two different records for single re-dispatch request.

What should be done to solve or improve this?

  1. Developer should be able to decide should the first request appear.
  2. And can decide should it marked with (REDISPATCHED)

Credits

Thanks for Tommy reporting this issue, related to #1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.