Commit Graph

254 Commits

Author SHA1 Message Date
santsai
f3ff42f93a getHost() now returns full host & port information (#383)
Previously, getHost only returned the host. As it now returns the
port as well, any .Host matches on a route will need to be updated
to also support matching on the port for cases where the port is
non default, eg: 80 for http or 443 for https.
2019-01-04 07:08:45 -08:00
tomare
ef912dd76e [bugfix] Clear matchErr when traversing subrouters.
Previously, when searching for a match, matchErr would be erroneously set, and prevent middleware from running (no match == no middleware runs).

This fix clears matchErr before traversing the next subrouter in a multi-subrouter router.
2018-12-27 16:42:16 -08:00
Raees
a31c1782bf Replace domain.com with example.com (#434)
Because domain.com is an actual business, example.com should be used for example purposes.
2018-12-25 08:41:17 -08:00
Michael Li
6137e193cd remove redundant code that remove support gorilla/context (#427)
* remove redundant code that remove support gorilla/context

* backward compatible for remove redundant code
2018-12-17 09:42:43 -05:00
Matt Silverlock
d2b5d13b92 Update and rename stale to stale.yml (#425) 2018-12-08 12:40:53 -08:00
Matt Silverlock
419fd9fe2a Add stalebot config (#424) 2018-12-07 08:41:48 -08:00
Joe Wilner
758eb64354 Improve subroute configuration propagation #422
* Pull out common shared `routeConf` so that config is pushed on to child
routers and routes.
* Removes obsolete usages of `parentRoute`
* Add tests defining compositional behavior
* Exercise `copyRouteConf` for posterity
2018-12-07 09:48:26 -06:00
kanozec
3d80bc801b Use subtests in mux_test.go (#415) 2018-10-30 08:25:28 -07:00
Nguyen Ngoc Trung (Steven)
521ea7b17d Use constant for 301 status code in regexp.go (#412) 2018-10-23 19:08:00 -07:00
Kamil Kisiel
deb579d6e0 README.md: Update site URL 2018-10-12 08:31:51 -07:00
Matt Silverlock
9e1f5955c0 Always run on the latest stable Go version. (#402)
Only run vet on the latest Go version.
2018-09-03 08:43:05 -07:00
Matt Silverlock
cf6680bc62 Create release-drafter.yml (#399) 2018-09-02 15:36:45 -07:00
Franklin Harding
8771f97498 Drop support for Go < 1.7: remove gorilla/context (#391)
* Drop support for Go < 1.7: remove gorilla/context
* Remove Go < 1.7 from Travis CI config
* Remove unneeded _native from context files
2018-09-02 15:22:40 -07:00
Shalom Yerushalmy
962c5bed07 Add 1.11 to build in travis (#398) 2018-08-30 07:23:24 -07:00
Kamil Kisiel
e48e440e4c Add test for multiple calls to Name().
Fixes #394
2018-08-07 00:52:56 -07:00
Kamil Kisiel
815b8c6a26 Clarify behaviour of Name method if called multiple times. 2018-08-07 00:50:18 -07:00
Matt Silverlock
cb4698366a Update LICENSE & AUTHORS files. (#386) 2018-06-05 14:15:56 -07:00
Jim Kalafut
e0b5abaaae Initialize user map (#371) 2018-05-26 15:17:21 -07:00
Matt Silverlock
c85619274f [deps] Add go.mod for versioned Go (#376) 2018-05-17 10:36:23 -07:00
Matt Silverlock
e3702bed27 [docs] Improve docstrings for middleware, skipclean (#375) v1.6.2 2018-05-12 20:22:33 -07:00
Sean Walberg
fdeb7bc314 [docs] Doc fix for testing variables in path (#374)
The example in the README does not pass the request through a mux therefore the request variables from the path are never populated. Update the sample to create a minimum viable router to use.

Fixes #373
2018-05-12 20:09:30 -07:00
Franklin Harding
5e55a4adb8 Add CORSMethodMiddleware (#366)
CORSMethodMiddleware sets the Access-Control-Allow-Methods response header
on a request, by matching routes based only on paths. It also handles
OPTIONS requests, by settings Access-Control-Allow-Methods, and then
returning without calling the next HTTP handler.
2018-05-11 18:30:14 -07:00
Matt Silverlock
ded0c29b24 Fix linter issues (docs) (#370) 2018-04-30 20:11:36 -07:00
Matt Silverlock
b57cb1605f [build] Update Go versions; add 1.10.x (#364) 2018-04-16 13:45:19 -07:00
brandon-height
94231ffd98 Fix table-driven example documentation (#363)
Prior to this change, the example documentation
found in the README.md has an errant code which
won't work in the table-driven code example.

This change modifies the variable name from `t` to `tc`
so it does not conflict with the `t *testing.T` struct
definition.

* Adds a range clause to the `for` statement
* Modifies `for` statement scope to use `tc.shouldPass`, and `tc.routeVariable`

Doc: https://github.com/gorilla/mux#testing-handlers
2018-04-03 11:23:30 -07:00
Johan Svensson
4dbd923b0c Make Use() variadic (#355)
Enables neater syntax when chaining several middleware functions.
2018-03-14 09:31:26 -07:00
Geon Kim
07ba1fd60e Modify http status code to variable in README (#350)
* Modify http status code to variable

* Modify doc

* Modify README
2018-02-25 21:11:51 -08:00
Geon Kim
d284fd8421 Modify 403 status code to const variable (#349)
* Modify http status code to variable

* Modify doc
2018-02-25 08:08:54 -08:00
Kamil Kisiel
c0091a0299 Create authentication middleware example. (#340)
* Create authentication middleware example.

For #339

* Fix example test filename.
2018-01-19 23:58:19 -08:00
Franklin Harding
0fdf828bb2 [docs] Clarify SetURLVars (#335)
* [docs] Clarify SetURLVars

Clarify in documentation that SetURLVars does not modify the given
*htttp.Request, provide an example of usage.

* Short and sweet function doc, example test.
2018-01-19 22:28:49 -08:00
Kamil Kisiel
077b44c2cf [docs] Document route.Get* methods consistently (#338)
They actually return an error instead of an empty list. `GetMethods` happened to not return an error, but it should for consistency, so I added that as well.
2018-01-19 20:51:41 -08:00
Kamil Kisiel
dc83507598 [docs] README.md: Improve "walking routes" example. (#337) (#323)
Fixes #323.

Also removed the duplicate "listing routes" example.
2018-01-19 20:47:48 -08:00
safeoy
3dbb9ed96e README.md: add miss "time" (#336) 2018-01-19 20:20:16 -08:00
Matt Silverlock
ad8790881f [docs] Fix doc.go (#333)
Addresses https://github.com/gorilla/mux/pull/294#discussion_r162309666
2018-01-18 09:53:57 -08:00
Matt Silverlock
69dae3b874 [docs] Add testing example (#331) 2018-01-16 23:16:36 -08:00
Matt Silverlock
63c5c2f1f0 [docs] Fix Middleware docs typos (#332) 2018-01-16 23:16:06 -08:00
Kamil Kisiel
85e6bfff1a Update doc.go: r.AddMiddleware(...) -> r.Use(...) 2018-01-16 17:18:53 -08:00
Kush Mansingh
0b74e3d0fe Make shutdown docs compilable (#330) 2018-01-16 14:43:47 -08:00
Roberto Santalla
53c1911da2 [feat] Add middleware support as discussed in #293 (#294)
* mux.Router now has a `Use` method that allows you to add middleware to request processing.
v1.6.1
2018-01-16 09:23:47 -08:00
Matt Silverlock
5bbbb5b2b5 [docs] Add graceful shutdown example (#329) 2018-01-07 07:57:08 -08:00
Kamil Kisiel
512169e5d7 refactor routeRegexp, particularily newRouteRegexp. (#328)
The existing options matchPrefix, matchHost, and matchQueries are
mutually exclusive so there's no point in having a separate boolean
argument for each one. It's clearer if there's a single type variable.

strictSlash and useEncodedPath were also being passed as naked bools so
I've wrapped these in a struct called routeRegexpOptions for more clarity
at the call site.
2018-01-05 10:40:59 -08:00
Zak Chitty
5ab525f4fb Public test API to set URL params (#322)
* Add a function to set url params for test

* [docs] add justification for SetURLVars and description of alternative approach to setting url vars.
* rename SetURLParams to SetURLVars as this is more descriptive.
* rename testing to testing_helpers as this is more descriptive.

* [docs] add stipulation to SetURLVars that it should only be used for testing purposes
2017-12-08 08:08:15 -08:00
Matthew
7904d2e42e [docs] Add example usage for Route.HeadersRegexp (#320)
* Add example usage for Route.HeadersRegexp

* Improve example_route_test.go style
2017-12-04 08:11:14 -08:00
Matt Silverlock
c572efe429 [docs] Note StrictSlash re-direct behaviour #308 (#321)
* [docs] Note StrictSlash re-direct behaviour #308

* StrictSlash enabled routes return a 301 to the client
* As per the HTTP standards, non-idempotent methods, such as POST or PUT, will be followed with a GET by the client
* Users should use middleware if they wish to change this behaviour to return a HTTP 308.

* Update description of StrictSlash
2017-12-02 12:38:52 -08:00
Matt Silverlock
65ec7248c5 Create ISSUE_TEMPLATE.md (#318) 2017-11-28 16:00:09 -08:00
Matthew
4a3d4f3dd2 [bugfix] Fix method subrouter handler matching (#300) (#317)
* Test method-based subrouters for multiple matching paths

* Pass TestMethodsSubrouter

* Change http.Method* constants to string literals
- Make compatible with Go v1.5

* Make TestMethodsSubrouter stateless and concurrent

* Remove t.Run and break up tests for concurrency

* Use backticks to remove quote escaping

* Remove global method handlers and HTTP method constants
2017-11-28 11:51:17 -08:00
Chris Dostert
2d5fef06b8 [docs] fix outdated UseEncodedPath method docs (#314)
https://github.com/gorilla/mux/pull/306 changed UseEncodedPath to use native go encoded path handling so cautions in it's docs are no longer applicable.
2017-11-08 19:54:02 -08:00
Roberto Santalla
7f08801859 MatchErr is set to ErrNotFound if NotFoundHandler is used (#311) v1.6.0 2017-11-05 09:23:20 -08:00
Kamil Kisiel
9f48112f18 [docs] Document router.Match (#313)
* Document router.Match

The return values are getting confusing. Hopefully this helps.

* Simplify some language.

* Remove double the
2017-11-04 21:08:26 -07:00
Matt Silverlock
bc452d92e3 [build] Allow tip failures (#312)
[build] Allow tip failures
2017-11-04 13:51:27 -07:00