diff --git a/README.md b/README.md index 195a8bf..3ffb212 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ##LARS -![Project status](https://img.shields.io/badge/version-2.7-green.svg) +![Project status](https://img.shields.io/badge/version-2.8-green.svg) [![Build Status](https://semaphoreci.com/api/v1/projects/4351aa2d-2f94-40be-a6ef-85c248490378/679708/badge.svg)](https://semaphoreci.com/joeybloggs/lars) [![Coverage Status](https://coveralls.io/repos/github/go-playground/lars/badge.svg?branch=master)](https://coveralls.io/github/go-playground/lars?branch=master) [![Go Report Card](https://goreportcard.com/badge/go-playground/lars)](https://goreportcard.com/report/go-playground/lars) diff --git a/group.go b/group.go index bf50238..3e7560d 100644 --- a/group.go +++ b/group.go @@ -131,6 +131,13 @@ func (g *routeGroup) Trace(path string, h ...Handler) { g.handle(TRACE, path, h) } +// Handle allows for any method to be registered with the given +// route & handler. Allows for non standard methods to be used +// like CalDavs PROPFIND and so forth. +func (g *routeGroup) Handle(method string, path string, h ...Handler) { + g.handle(method, path, h) +} + // Any adds a route & handler to the router for all HTTP methods. func (g *routeGroup) Any(path string, h ...Handler) { g.Connect(path, h...) diff --git a/lars_test.go b/lars_test.go index 8f17d96..55a3471 100644 --- a/lars_test.go +++ b/lars_test.go @@ -428,6 +428,8 @@ func TestBadAdd(t *testing.T) { } func TestAddAllMethods(t *testing.T) { + + propfind := "PROPFIND" fn := func(c Context) { if _, err := c.Response().Write([]byte(c.Request().Method)); err != nil { panic(err) @@ -446,6 +448,7 @@ func TestAddAllMethods(t *testing.T) { l.Patch("/home/", fn) l.Options("/home/", fn) l.Connect("/home/", fn) + l.Handle(propfind, "/home/", fn) code, body := request(GET, "/", l) Equal(t, code, http.StatusOK) @@ -486,6 +489,10 @@ func TestAddAllMethods(t *testing.T) { code, body = request(CONNECT, "/home/", l) Equal(t, code, http.StatusOK) Equal(t, body, CONNECT) + + code, body = request(propfind, "/home/", l) + Equal(t, code, http.StatusOK) + Equal(t, body, propfind) } func TestAddAllMethodsMatch(t *testing.T) {