Skip to content

Commit 0a70280

Browse files
Test and document custom HTTP verb compliance
1 parent ffba94e commit 0a70280

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ import (
3333
func main() {
3434
mux := methodmux.New()
3535

36-
getHandler := myNewGetHandler()
37-
3836
mux.Handle(http.MethodGet, "/some-endpoint/", getHandler)
37+
mux.Handle("MYMETHOD", "/some-endpoint/", myMethodHandler)
3938
mux.HandleFunc(http.MethodPost, "/some-endpoint/", func(rw http.ResponseWriter, req *http.Request) {
4039
fmt.Fprintf(rw, "Hi! This the response to a POST call.")
4140
})

mux.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ Example usage:
1414
func main() {
1515
mux := methodmux.New()
1616
17-
getHandler := myNewGetHandler()
18-
1917
mux.Handle(http.MethodGet, "/some-endpoint/", getHandler)
18+
mux.Handle("MYMETHOD", "/some-endpoint/", myMethodHandler)
2019
mux.HandleFunc(http.MethodPost, "/some-endpoint/", func(rw http.ResponseWriter, req *http.Request) {
2120
fmt.Fprintf(rw, "Hi! This the response to a POST call.")
2221
})

mux_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func TestServe(t *testing.T) {
8383
{"POST", "example.com", "/get-only", 405, ""},
8484
{"PATCH", "example.com", "/get-only", 405, ""},
8585

86+
{"MYMETHOD", "example.com", "/dir/", 413, "/dir/"},
87+
8688
// The /foo -> /foo/ redirect applies to CONNECT requests
8789
// but the path canonicalization does not.
8890
{"CONNECT", "example.com", "/dir", 301, "/dir/"},
@@ -111,6 +113,7 @@ func TestServe(t *testing.T) {
111113
{"PATCH", "sub.example.com/", serve(416)},
112114
{"CONNECT", "/dir/", serve(200)},
113115
{"CONNECT", "/search", serve(201)},
116+
{"MYMETHOD", "/dir/", serve(413)},
114117
}
115118

116119
for _, tc := range testCases {

0 commit comments

Comments
 (0)