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

Allow arbitrary HTTP method types to be added as routes #2237

Merged
merged 1 commit into from Aug 10, 2022

Conversation

aldas
Copy link
Contributor

@aldas aldas commented Aug 6, 2022

Allow arbitrary HTTP method types to be added as routes.

This does not affect routing "usual" use-case performance as these arbitrary HTTP method types and underlying map is accessed only when request is of that type. This code is taken from v5.

Relates to;

Example:

import (
	"fmt"
	"github.com/labstack/echo/v4"
	"log"
	"net/http"
)

func main() {
	e := echo.New()

	e.Add("COPY", "/*", func(c echo.Context) error {
		return c.String(http.StatusOK, "OK COPY")
	})

	if err := e.Start(":8080"); err != http.ErrServerClosed {
		log.Print(fmt.Errorf("error when starting HTTP server: %w", err))
	}
}

Output:

x@x:~/code/$ curl -v -X COPY "http://localhost:8080/something"
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> COPY /something HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: text/plain; charset=UTF-8
< Date: Sat, 06 Aug 2022 20:34:24 GMT
< Content-Length: 7
< 
* Connection #0 to host localhost left intact
OK COPY

@codecov
Copy link

codecov bot commented Aug 6, 2022

Codecov Report

Merging #2237 (8742207) into master (a9879ff) will increase coverage by 0.12%.
The diff coverage is 76.92%.

@@            Coverage Diff             @@
##           master    #2237      +/-   ##
==========================================
+ Coverage   92.34%   92.46%   +0.12%     
==========================================
  Files          37       37              
  Lines        3123     3134      +11     
==========================================
+ Hits         2884     2898      +14     
+ Misses        150      145       -5     
- Partials       89       91       +2     
Impacted Files Coverage Δ
echo.go 95.19% <ø> (ø)
router.go 97.63% <76.92%> (+0.88%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@aldas
Copy link
Contributor Author

aldas commented Aug 6, 2022

@lammel could you review this PR?

@aldas
Copy link
Contributor Author

aldas commented Aug 10, 2022

bump @lammel , if you are on summer vacation do not reply :) I'll merge this today and bump a new release.

Copy link
Contributor

@lammel lammel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pure code review LGTM.

This means we really support any aribtrary HTTP method, even those not known of defined in any standard.

Should we limit the methods to a list of supported additional methods (like those specified for WebDAV)?

@aldas
Copy link
Contributor Author

aldas commented Aug 10, 2022

To me, it does not make sense or reason to limit it - if you want to support some proprietary method in your app then go ahead.

@aldas aldas merged commit cba12a5 into labstack:master Aug 10, 2022
@aldas aldas deleted the support_any_method branch December 29, 2022 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants