1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-28 08:38:39 +02:00
Commit Graph

114 Commits

Author SHA1 Message Date
Brie Taylor
08093a4a1d Return an empty string for ctx.path if there is no registered path 2023-01-28 18:15:49 +02:00
toimtoimtoim
f1cf1ec930 Fix adding route with host overwrites default host route with same method+path in list of routes. 2022-12-25 22:19:15 +02:00
toimtoimtoim
cba12a570e Allow arbitrary HTTP method types to be added as routes 2022-08-10 22:04:06 +03:00
Martti T
70acd57105
Fix case when routeNotFound handler is lost when new route is added to the router (#2219) 2022-07-13 08:16:27 +03:00
Martti T
690e3392d9
Add support for registering handlers for 404 routes (#2217) 2022-07-12 21:53:41 +03:00
Artem Iurin
9bf1e3c8ce
Allow different param names in different methods with same path scheme (#2209)
* Change methodHandler element type to methodContext

Signed-off-by: ortyomka <iurin.art@gmail.com>

* Allow different param names in the smae path with different methods

Signed-off-by: ortyomka <iurin.art@gmail.com>

* Rename methodContext to routeMethod
Add paramsCount in each node for perfomance

Signed-off-by: ortyomka <iurin.art@gmail.com>

* Add backtracking to nearest path

Signed-off-by: ortyomka <iurin.art@gmail.com>

* Remove params from NotAllowed

Signed-off-by: ortyomka <iurin.art@gmail.com>
2022-07-11 20:25:41 +03:00
eric
54efc3850d
remove some unused code (#2116)
* remove unused code
2022-03-13 15:31:39 +02:00
toimtoimtoim
5b26a5257b Allow header support in Router, MethodNotFoundHandler (405) and CORS middleware 2022-01-03 21:04:17 +02:00
toimtoimtoim
6b5e62b27e fix: route containing escaped colon should be matchable but is not matched to request path (fixes #2046) 2021-12-17 14:49:17 +02:00
Martti T
9fc4672195
Allow escaping of colon in route path so Google Cloud API "custom methods" https://cloud.google.com/apis/design/custom_methods can be implemented (resolves #1987) (#1988)
Allow escaping of colon in route path so Google Cloud API "custom methods" https://cloud.google.com/apis/design/custom_methods could be implemented (resolves #1987)
2021-09-19 11:39:12 +03:00
Martti T
643066594d
Fix router not matching param route with trailing slash and implement matching by path+method (#1812)
* when url ends with slash first param route is the match (fix #1804)
* router should check if method is suitable for matching route and if not then continue search in tree (fix #1808)
2021-04-27 09:55:31 +02:00
Martti T
664cf8c106
Refactor router for readability (#1796)
* refactor router tests to table driven (this way it is easier to debug test cases with breakpoints)
* refactor router variables to be more readable
2021-03-06 00:43:59 +01:00
Martti T
6f9b71cd6f
Poc router stack backtracking (#1791)
Router: PoC stack based backtracking

Co-authored-by: stffabi <stffabi@users.noreply.github.com>
2021-03-02 20:56:40 +02:00
stffabi
a9df83037d
Do not handle special trailing slash case for partial prefix (#1741)
* Add tests for issue #1739
* Handle special trailing slash case only for a matching prefix

Only handle the special trailing slash case if the whole prefix matches to avoid matching   
a wrong route for overlapping prefixes, e.g. /users/* for the path /users_prefix/ where
the route is only a partial prefix of the requested path.
2021-01-03 19:35:00 +01:00
Roland Lammel
03ce9b25eb
Merge pull request #1661 from pafuent/fix_router_find_after_invalid_set_param_values
Fixed Router#Find panic an infinite loop
2020-12-16 10:11:25 +01:00
Pablo Andres Fuente
53653b3df6 Merge branch 'master' into fix_router_find_after_invalid_set_param_values 2020-12-16 01:56:28 +00:00
Pablo Andres Fuente
71325a6f1e erge branch 'master' into routing_misses_performance_improvements 2020-12-14 03:36:12 +00:00
Pablo Andres Fuente
3a6100bebe Improving routing performance and benchmark suite
Before this commit, all the node types were added to the same list of
children nodes. Taking in consideration that only one Param and Any type
of node could exist per node, two new node struct field were added to hold
the references to those kind of nodes.
This avoid the need to iterate through all the Static type nodes just to
find one Param or Any type node. Those iterations could be performed
multiple times in the same iteration of Router#Find.
Removing the route comments of the Router benchmark tests.
Updating the Router benchmarks tests to find the routes defined to each
particular benchmark. Before, all the benchmarks tried to find only the
GitHub API.
Adding new router benchmarks to measure when the Router try to find
routes that are not registered.
2020-11-22 03:09:33 +00:00
Pablo Andres Fuente
23c21871b7 Fixed Router#Find panic an infinite loop
Before this fix, Router#Find panics or enters in an infinite loop when
the context params values were set to a number less than the max number
of params supported by the Router.
2020-10-28 04:30:41 +00:00
Pablo Andres Fuente
85e521f384 Fixed panic when Router#Find fails on Param paths
Fixed panic when Router#Find fails to find a route that could match a
Param route that only have children routes and no root route.
e.g
/create
/:id/edit
/:id/active

Finding /creates results in panic because the router tree node that
belongs to the param route :id don't have pnames on it. The childrens of
:id (:id/edit and :id/active) have the pnames properly set, but those
are not processed because /creates don't match on those paths.
2020-10-25 04:14:15 +00:00
Roland Lammel
43e32ba83d
Fix #1526 trailing slash to any route (#1563)
* refs #1526: Add tests for trailing slash requests with nested any routes

* refs #1526: Handle specual router case with trailing slash for non-root any route

* refs #1526: Fix accidential lookup for any route without trailing slash in request
2020-05-06 14:01:28 -07:00
Roland Lammel
5ddc3a68ba
Fix routing conflict for dynamic routes and static route with common prefix (#1509) (#1512)
* Add test for issue #1509 for dynamic routes and multiple static routes with common prefix

* Fix #1509: routing conflict for dynamic routes and static route with common prefix

* Improve routing performance for static only route trees
2020-02-24 08:26:49 -08:00
Roland Lammel
f4b5a90ad3
Fix #1493 router loop for param routes (#1501)
* Add test to reproduce router loop for #1493

* Simplify and correct  router param tests

* Fix #1493 to avoid router loop for param nodes
2020-02-19 07:10:57 -08:00
Ajitem Sahasrabuddhe
5bf6888444 Parameterized routes sometimes return 404 (#1480)
* url param bug

* add comment

* add tests

* Bump echo version
2020-01-23 16:13:18 -08:00
Ajitem Sahasrabuddhe
5793765eed Fix param value bug (#1467)
* set parameter value in the pvalues slice

* update echo version

* update travis yml to fix failing build and add go modules support

* Add tests

* Update router_test.go

Co-authored-by: Vishal Rana <vr@labstack.com>
2020-01-01 08:57:00 -08:00
Roland Lammel
86b200fa0d Merge branch 'bugfix/1412-route-matchany-multilevel' of github.com:neotel-at/echo into bugfix/1412-route-matchany-multilevel 2019-12-27 16:41:31 +01:00
Roland Lammel
ccf6f1a77d refs #1412: Fix parent nodes for route insert on node split 2019-10-16 22:35:30 +02:00
Roland Lammel
8d47b34cdc refs #1412: Fix multi level match any routes 2019-10-16 22:35:30 +02:00
Roland Lammel
16ed3a8049 refs #1412: Fix multi level match any routes 2019-10-03 19:30:46 +02:00
Letian Zhang
8cabd1e123 don't make router parse duplicated param when backtracing happens #1368 (#1369) 2019-07-25 13:39:03 -07:00
Vishal Rana
207a141d5d Closed #1348
Signed-off-by: Vishal Rana <vr@labstack.com>
2019-07-17 21:18:56 -07:00
Michał Adamski
e1d21a73cf tests and fix for findChildByKind executed on nil node 2019-03-01 08:27:11 +01:00
Emir Ribić
c8fd197fa8 Replace http constants with stdlib ones, i.e.: http.MethodGet instead of echo.GET (#1205) 2018-10-14 20:46:58 +05:30
Shogo Nagasaka
af5c97715f Fix node's parameter names assignment problem. (#1201) 2018-10-07 08:34:30 +05:30
Vishal Rana
7c3df7703f Revert "Allow parameter routes to end with a dot (/foo/:id.json)"
This reverts commit bfa14633f3.
2018-04-11 22:34:26 -07:00
Martin Tournoij
bfa14633f3 Allow parameter routes to end with a dot (/foo/:id.json)
Currently a route in the form of `/foo/:id.json` means echo will detect
the parameter name `id.json` instead of the expected `id`. I think this
is rather counter-intuitive, as adding an extension to paths is a fairly
common use case.

With this change both a `/` and a `.` will be treated as the end of a
parameter name.

Benchmark before this change:

	$ go test -bench .
	[..]

	goos: linux
	goarch: amd64
	pkg: github.com/labstack/echo
	BenchmarkRouterStaticRoutes-4             100000             17743 ns/op               0 B/op          0 allocs/op
	BenchmarkRouterGitHubAPI-4                 50000             33081 ns/op               1 B/op          0 allocs/op
	BenchmarkRouterParseAPI-4                 300000              5370 ns/op               0 B/op          0 allocs/op
	BenchmarkRouterGooglePlusAPI-4            200000              9183 ns/op               0 B/op          0 allocs/op
	PASS
	ok      github.com/labstack/echo        8.565s

After this change:

	goos: linux
	goarch: amd64
	pkg: github.com/labstack/echo
	BenchmarkRouterStaticRoutes-4             100000             17699 ns/op               0 B/op          0 allocs/op
	BenchmarkRouterGitHubAPI-4                 50000             32962 ns/op               1 B/op          0 allocs/op
	BenchmarkRouterParseAPI-4                 300000              5450 ns/op               0 B/op          0 allocs/op
	BenchmarkRouterGooglePlusAPI-4            200000              9205 ns/op               0 B/op          0 allocs/op
	PASS
	ok      github.com/labstack/echo        8.590s

Fixes #599
2018-04-10 11:37:35 -07:00
Vishal Rana
687f05470a Zhaojkun httperror message (#959)
* Change echo http error message

* Add test case

* Fixed test cases

Signed-off-by: Vishal Rana <vr@labstack.com>
2017-06-20 08:58:53 -07:00
Vishal Rana
1b70cbebbe Fixed #954
Signed-off-by: Vishal Rana <vr@labstack.com>
2017-06-14 16:30:53 -07:00
Vishal Rana
f9e97332f3 fixed #729
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-11-15 20:12:13 -08:00
Vishal Rana
c5a3575d4c updated migration guide
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-11-14 22:54:09 -08:00
Vishal Rana
0fca54f389 updated docs, readme and benchmark tests
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-11-12 09:47:49 -08:00
Vishal Rana
954efac63a fixed #684
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-10-22 15:18:55 -07:00
Vishal Rana
36251e88e2 router changes
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-10-21 20:36:49 -07:00
Vishal Rana
2bdbf6918e fixed #623
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-10-14 14:52:40 -07:00
Vishal Rana
2eb87f8036 param wildcard capture fixed to *
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-10-10 18:36:48 -07:00
Vishal Rana
8623669cbc removed Context#P()
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-10-10 18:22:13 -07:00
Vishal Rana
15eb5b0aad removed embedded context and exposed SetRequest in context
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-10-10 17:31:26 -07:00
Vishal Rana
09a2ce60a6 About context #500
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-06-05 13:47:59 -07:00
Vishal Rana
682a5580b7 Deprecated Echo#GetContext() => Echo#AcquireContext(), Echo#PutContext() => Echo#ReleaseContext()
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-05-03 17:23:31 -07:00
Vishal Rana
467cf05b41 Changes based on comments for #430
Signed-off-by: Vishal Rana <vr@labstack.com>
2016-04-16 15:56:09 -07:00