Skip to content

Commit

Permalink
Add Handle function for adding non standard methods such as PROPFIND …
Browse files Browse the repository at this point in the history
…for CalDav
  • Loading branch information
joeybloggs authored and joeybloggs committed May 13, 2016
1 parent b910f1b commit 78ede96
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##LARS
<img align="right" src="https://raw.githubusercontent.com/go-playground/lars/master/examples/README/test.gif">
![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)
Expand Down
7 changes: 7 additions & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
7 changes: 7 additions & 0 deletions lars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 78ede96

Please sign in to comment.