Skip to content

Commit 78ede96

Browse files
joeybloggsjoeybloggs
authored andcommitted
Add Handle function for adding non standard methods such as PROPFIND for CalDav
1 parent b910f1b commit 78ede96

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
##LARS
22
<img align="right" src="https://raw.githubusercontent.com/go-playground/lars/master/examples/README/test.gif">
3-
![Project status](https://img.shields.io/badge/version-2.7-green.svg)
3+
![Project status](https://img.shields.io/badge/version-2.8-green.svg)
44
[![Build Status](https://semaphoreci.com/api/v1/projects/4351aa2d-2f94-40be-a6ef-85c248490378/679708/badge.svg)](https://semaphoreci.com/joeybloggs/lars)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/lars/badge.svg?branch=master)](https://coveralls.io/github/go-playground/lars?branch=master)
66
[![Go Report Card](https://goreportcard.com/badge/go-playground/lars)](https://goreportcard.com/report/go-playground/lars)

group.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ func (g *routeGroup) Trace(path string, h ...Handler) {
131131
g.handle(TRACE, path, h)
132132
}
133133

134+
// Handle allows for any method to be registered with the given
135+
// route & handler. Allows for non standard methods to be used
136+
// like CalDavs PROPFIND and so forth.
137+
func (g *routeGroup) Handle(method string, path string, h ...Handler) {
138+
g.handle(method, path, h)
139+
}
140+
134141
// Any adds a route & handler to the router for all HTTP methods.
135142
func (g *routeGroup) Any(path string, h ...Handler) {
136143
g.Connect(path, h...)

lars_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ func TestBadAdd(t *testing.T) {
428428
}
429429

430430
func TestAddAllMethods(t *testing.T) {
431+
432+
propfind := "PROPFIND"
431433
fn := func(c Context) {
432434
if _, err := c.Response().Write([]byte(c.Request().Method)); err != nil {
433435
panic(err)
@@ -446,6 +448,7 @@ func TestAddAllMethods(t *testing.T) {
446448
l.Patch("/home/", fn)
447449
l.Options("/home/", fn)
448450
l.Connect("/home/", fn)
451+
l.Handle(propfind, "/home/", fn)
449452

450453
code, body := request(GET, "/", l)
451454
Equal(t, code, http.StatusOK)
@@ -486,6 +489,10 @@ func TestAddAllMethods(t *testing.T) {
486489
code, body = request(CONNECT, "/home/", l)
487490
Equal(t, code, http.StatusOK)
488491
Equal(t, body, CONNECT)
492+
493+
code, body = request(propfind, "/home/", l)
494+
Equal(t, code, http.StatusOK)
495+
Equal(t, body, propfind)
489496
}
490497

491498
func TestAddAllMethodsMatch(t *testing.T) {

0 commit comments

Comments
 (0)