1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-18 16:20:53 +02:00
Commit Graph

170 Commits

Author SHA1 Message Date
Behnam
f7d9f5142e
optimization: struct alignment (#2636)
(#2632)
2024-05-30 22:50:01 +03:00
Martti T
447c92d842
When route is registered with empty path it is normalized to /. Make sure that returned echo.Route structs reflect that behavior. (#2616) 2024-03-27 12:28:46 +02:00
Martti T
3598f295f9
Change type definition blocks to single declarations. This helps copy/pasting Echo code in examples. (#2606) 2024-03-09 07:53:07 -08:00
Martti T
a842444e8f
Add SPDX licence comments to files. See https://spdx.dev/learn/handling-license-info/ (#2604) 2024-03-09 11:21:24 +02:00
cui fliter
0d47b7e6a9 fix misuses of a vs an
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-04-22 21:37:45 +03:00
Mihard
7d54690cdc
Proper colon support in reverse (#2416)
* Adds support of the escaped colon in echo.Reverse

---------

Co-authored-by: Mihard <mihard@webird.ru>
2023-04-16 21:13:47 +03:00
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
lkeix
0644cd6ecd
fix: duplicated findStaticChild process at findChildWithLabel (#2176) 2022-05-27 20:15:58 +03:00
sivchari
f3865f9aa5
Minor syntax fixes (#1994) 2022-01-24 10:33:13 +01: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
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
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
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
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
Vishal Rana
ae55310e59 Merge branch 'master' of https://github.com/meehow/echo into meehow-master 2019-07-17 18:31:55 -07:00
kolaente
610d67f17f Added support for the REPORT method (#1332) 2019-06-09 09:11:18 -07:00
Vishal Rana
5d2c33ad5d Bumped v4.1.5
Signed-off-by: Vishal Rana <vr@labstack.com>
2019-04-29 22:54:49 -07:00
Vishal Rana
6f0a227a5a Built-in capability to run multiple hosts
Signed-off-by: Vishal Rana <vr@labstack.com>
2019-04-28 22:22:35 -07:00
Michał Adamski
e1d21a73cf tests and fix for findChildByKind executed on nil node 2019-03-01 08:27:11 +01:00
Geon Kim
82917fd848 Delete useless goto statements (#1208) 2018-10-15 09:12:43 +05:30
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
Vishal Rana
28d07c3bca Revert "Fix parameter routes with an extension (/foo/:id.json)"
This reverts commit cf7b55584d.
2018-04-11 22:34:26 -07:00
Vishal Rana
a8aaeb8a26 Revert "Revert "Fix parameter routes with an extension (/foo/:id.json)""
This reverts commit f526774740.
2018-04-11 22:34:26 -07:00
Vishal Rana
f526774740 Revert "Fix parameter routes with an extension (/foo/:id.json)"
This reverts commit cf7b55584d.
2018-04-11 22:32:19 -07:00
Martin Tournoij
cf7b55584d Fix parameter routes with an extension (/foo/:id.json)
This is a follow-up to #1101. It turns out that that patch is
incomplete, as a similar check also needs to be added in the
`Router.Add()` method.

I don't understand why the test works fine, but when using it in a real
application. For example with this example:

	func main() {
		e := echo.New()
		e.GET("/xxx/:id.json", func(c echo.Context) error {
			return c.String(200, fmt.Sprintf("%#v: names: %#v; vals: %#v",
				c.Path(), c.ParamNames(), c.ParamValues()))
		})
		log.Fatal(e.Start(":8000"))
	}

Gives a 404 on `/xxx/42.json`, and for `/xxx/42` it gives the output:

	/xxx/:id.json": names: []string{"id.json"}; vals: []string{"42"}

It makes sense to add the test there too; I just don't get why the test
cases that I added in ##1101 *does* produce the correct output :-/
2018-04-10 14:54:01 -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
bdb49be734 Added PROPFIND method
Signed-off-by: Vishal Rana <vr@labstack.com>
2018-03-13 12:45:47 -07:00
Vishal Rana
4f3080c197 Bit of more cleanup
Signed-off-by: Vishal Rana <vr@labstack.com>
2018-02-21 11:38:22 -08:00
Evgeniy Kulikov
f49d166e6f [FIX] Cleanup code (#1061)
Code cleanup
2018-02-21 10:44:17 -08:00