Commit Graph

82 Commits

Author SHA1 Message Date
Benjamin Boudreau
15a353a636 adding Router.Name to create new Route (#457) 2019-02-28 10:12:03 -08:00
moeryomenko
a7962380ca replace rr.HeaderMap by rr.Header() (#443) 2019-01-25 10:05:53 -06:00
Gregor Weckbecker
08e7f807d3 Ignore ErrNotFound while matching Subrouters (#438)
MatchErr is set by the router to ErrNotFound if no route matches. If
no route of a Subrouter matches the error can by safely ignored. This
implementation only ignores these errors and does not ignore other
errors like ErrMethodMismatch.
2019-01-08 08:29:30 -06:00
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
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
Kamil Kisiel
e48e440e4c Add test for multiple calls to Name().
Fixes #394
2018-08-07 00:52:56 -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
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
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
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
Roberto Santalla
7f08801859 MatchErr is set to ErrNotFound if NotFoundHandler is used (#311) 2017-11-05 09:23:20 -08:00
Paul B. Beskow
10490f55fa GetQueryTemplates and GetQueryRegexp extraction (#304)
Developers can now extract the query templates and regexps
from a router as lists of combined query pairs.
2017-10-19 18:19:04 -07:00
Pontus Leitzler
bdd5a5a1b0 Fix WriteHeader in TestA301ResponseWriter. (#301)
WriteHeader did only set status field for a local copy that was discared
upon return.
2017-10-08 14:49:13 -07:00
Matt Silverlock
bb285ea687 [docs] Fix missing space in docstring (#289) 2017-08-30 13:57:41 -07:00
Mayank Patel
a659b61323 Fix #271: Return 405 instead of 404 when request method doesn't match the route 2017-08-29 22:39:17 -07:00
Chris Hines
ac112f7d75 Prefer scheme on child route when building URLs. 2017-07-04 00:43:45 -07:00
Chris Hines
37b3a6cace Use scheme from parent router when building URLs. 2017-07-04 00:43:45 -07:00
Chris Hines
18fca31550 Add test and fix for escaped query values.
Reproduces and fixes #238.
2017-06-02 12:31:40 -07:00
Pavel Ivanov
f9aa23a02b Add tests for support for queries in URL reversing. 2017-06-02 12:31:40 -07:00
Nick Miyake
4d814f7650 Update ancestors parameter for WalkFunc for matcher subrouters
Fixes #263
2017-05-22 08:17:48 -07:00
Nick Miyake
a322b2c2ec Update Walk to match all subrouters
Matches all routes instead of just routes with paths.

Fixes #261
2017-05-21 14:35:07 -07:00
Chris Hines
bcd8bc72b0 Support building URLs with non-http schemes. (#260)
* Move misplaced tests and fix comments.

* Support building URLs with non-http schemes.

- Capture first scheme configured for a route for use when building
  URLs.
- Add new Route.URLScheme method similar to URLHost and URLPath.
- Update Route.URLHost and Route.URL to use the captured scheme if
  present.

* Remove Route.URLScheme method.

* Remove UTF-8 BOM.
2017-05-20 21:50:13 -07:00
Bulat Gaifullin
b552615e22 Added method Route.GetMethods 2017-05-20 15:55:46 -07:00
Bulat Gaifullin
1856953e53 Added method Route.GetPathRegexp 2017-05-20 15:55:46 -07:00
Carlos Alexandro Becker
4c1c3952b7 fixed typo (#250) 2017-04-26 21:12:50 -07:00
Adam Eijdenberg
392c28fe23 [bugfix] fail fast if regex is incorrectly specified using capturing groups. (#218) 2017-01-18 05:43:44 -08:00
ShaneSaww
b9ff34f617 Adding some extra tests, to hit all the use cases 2017-01-16 21:11:35 -08:00
ShaneSaww
293ebe1493 Adding in a check for routes with just / 2017-01-15 21:47:00 -08:00
Kush Mansingh
0a192a1931 Add useEncodedPath option to router and routes (#190)
- Resolves a breaking change in #184
2016-09-02 08:33:43 -07:00
Richard Musiol
0b13a92220 Simplify extractVars, fixes edge cases. (#185)
Also make sure all regexp groups in tests are non-capturing.
2016-08-27 09:50:34 -07:00
Aaron Taylor
34bf6dc9fa make the getPath method safer, fixing panics within App Engine (#189) 2016-08-24 16:34:02 -07:00
Kush Mansingh
674ef1c280 Add mechanism to route based on the escaped path (#184)
* Add mechanism to route based on the escaped path, correct request mocking in tests

* Remove unneccessary regex matching, substitute with string slicing

* Add test case and handling for requests with no host/scheme
2016-08-24 06:45:17 -07:00
Kamil Kisiel
327d4b684c Clean up some naming in mux_test.go 2016-07-30 16:45:59 -07:00
Martin Hamrle
cf57124f1d Fix error handling in Router.Walk
In old version error was not returned properly, In one walkFn call
error was checked only for SkipRouter but not for nil.
2016-07-25 18:05:24 +02:00
Eric J. Holmes
fdfca9f917 Support native context.Context when go1.7 is used. 2016-06-04 15:38:01 +07:00
Matt Silverlock
9c19ed558d [feature] Add SkipClean option
- SkipClean skips cleaning routes (or a route) - e.g. when true, if the route path is "/path//to", it will remain with the double slash. This is helpful if you have a route like: /fetch/http://xkcd.com/534/
2016-05-02 10:56:24 -07:00
Jingwen Owen Ou
9935257381 Add test for SkipClean 2016-05-02 10:24:18 -07:00
JP Robinson
65c2651643 fixing regexp changes from PR #144 2016-03-07 16:38:03 -05:00
Dj Gilcrease
f84ab9ab62 Fix go fmt issues 2016-02-28 14:46:18 -08:00
Dj Gilcrease
0d60c4bfeb Add tests for GetPathTemplate. Added GetHostTemplate and associated tests as well 2016-02-28 14:42:09 -08:00
Nate Woods
82a9c170d4 Covering change with unit test
This test focuses on the feature of allowing sub-routers error handlers to precede the parents, rather than the code change required to provide this functionality.
2015-12-26 00:09:25 -07:00
mitsuteru sawa
a90bbbc6fa Correct a printf verb type
% go vet
mux_test.go:1080: arg len(ancestors) for printf verb %s of wrong type:
int
2015-11-07 21:34:30 +09:00
Kamil Kisiel
5112c33f3a slightly improve printing of regexps in failed tests. 2015-08-11 22:16:39 -07:00
Shinya Kawaguchi
577b9e4a65 Add tests for hyphenated variable names 2015-08-11 04:05:30 +09:00
Kamil Kisiel
8965bfef36 Merge branch 'subexp-fix' 2015-08-07 13:34:10 -07:00
Kamil Kisiel
c3c5f0000f Add test which used to fail for queries.
Fixes #66
2015-08-06 22:12:38 -07:00
Kamil Kisiel
e73f183699 fix use of capturing subexpressions in pattern matches.
The router now associates a regexp named group with each mux variable.
It only fills variables when capturing group name match instead of
relying on indices, which doesn't work if a variable regexp has interior
capturing groups.

Fixes #62
2015-08-06 20:32:43 -07:00
Kamil Kisiel
f15e0c4946 Merge pull request #100 from eastwood/master
Issue #16: Added regex support for matching headers
2015-07-27 09:40:50 -07:00
Kamil Kisiel
61445102e8 Merge pull request #111 from burrbd/master
Issue #109
2015-07-17 08:02:10 -07:00