Skip to content
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

Support for custom HTTP methods #1952

Closed
3 tasks done
mdouchement opened this issue Aug 10, 2021 · 1 comment
Closed
3 tasks done

Support for custom HTTP methods #1952

mdouchement opened this issue Aug 10, 2021 · 1 comment
Labels

Comments

@mdouchement
Copy link

Issue Description

The Router object does not allow custom HTTP methods like COPY or anything else.

func (n *node) addHandler(method string, h HandlerFunc) and func (n *node) findHandler(method string) HandlerFunc have static switch cases.

I know this is not a common use case.

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

Calls the handler defined by:

e.Add("COPY", "/*", func(c echo.Context) error {
	return c.NoContent(http.StatusCreated)
})

Actual behaviour

It returns echo.NotFoundHandler or echo.MethodNotAllowedHandler.

Steps to reproduce

Working code to debug

package main

import (
	"fmt"
	"net/http"
	"net/http/httputil"
	"time"

	"github.com/labstack/echo/v4"
)

func main() {
	e := echo.New()
	e.Add("COPY", "/*", func(c echo.Context) error {
		return c.NoContent(http.StatusCreated)
	})

	fmt.Println("Routes:")
	for _, route := range e.Routes() {
		fmt.Printf("%6s %s\n", route.Method, route.Path)
	}

	go func() {
		err := e.Start("localhost:5000")
		if err != nil {
			panic(err)
		}
	}()
	time.Sleep(time.Second)
	fmt.Println()

	//
	//
	//

	req, err := http.NewRequest("COPY", "http://localhost:5000/somepath", nil)
	if err != nil {
		panic(err)
	}

	payload, err := httputil.DumpRequest(req, false)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(payload))

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}

	payload, err = httputil.DumpResponse(resp, true)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(payload))
}

Version/commit

4.5.0

@aldas
Copy link
Contributor

aldas commented Aug 11, 2022

closing, from v4.8.0 this is possible. See #2237

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants