Skip to content

Simplify code of Add/Remove trailing slash and fix bug #1275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2019

Conversation

im-kulikov
Copy link
Contributor

@im-kulikov im-kulikov commented Feb 4, 2019

  • simplify code (more informative / understanding)
  • fix trailing slash bug
  • assert collides with imported package name (in tests)
  • fix unhandled errors

cc @vishr / @alexaandru

- simplify code (more informative / understanding)
- assert collides with imported package name (in tests)
- fix unhandled errors
@codecov
Copy link

codecov bot commented Feb 4, 2019

Codecov Report

Merging #1275 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1275   +/-   ##
=======================================
  Coverage   81.78%   81.78%           
=======================================
  Files          26       26           
  Lines        1933     1933           
=======================================
  Hits         1581     1581           
  Misses        243      243           
  Partials      109      109
Impacted Files Coverage Δ
middleware/slash.go 91.48% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc28fce...725b5d8. Read the comment docs.

@im-kulikov
Copy link
Contributor Author

and this PR fix next error:

package main

import (
	"fmt"
	"net/http"
	"net/http/httputil"
)

func check(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	cli := new(http.Client)

	req, err := http.NewRequest(http.MethodConnect, "http://localhost:8080", nil)
	check(err)

	data, err := httputil.DumpRequest(req, true)
	check(err)

	fmt.Println(string(data))

	res, err := cli.Do(req)
	check(err)

	data, err = httputil.DumpResponse(res, true)
	check(err)

	fmt.Println(string(data))
}
2019/02/05 03:19:25 http: panic serving [::1]:56897: runtime error: index out of range
goroutine 84 [running]:
net/http.(*conn).serve.func1(0xc000166000)
	/usr/local/Cellar/go/1.11.5/libexec/src/net/http/server.go:1746 +0xd0
panic(0x18783c0, 0x20938c0)
	/usr/local/Cellar/go/1.11.5/libexec/src/runtime/panic.go:513 +0x1b9
github.com/labstack/echo/v4/middleware.AddTrailingSlashWithConfig.func1.1(0x1a771a0, 0xc0001ac070, 0xc0001ac070, 0xc000075d38)
	/Users/kulikov/.golang/pkg/mod/github.com/labstack/echo/[email protected]/middleware/slash.go:52 +0x33b
github.com/labstack/echo/v4.(*Echo).ServeHTTP(0xc0003948c0, 0x1a676c0, 0xc000392000, 0xc00014e300)
	/Users/kulikov/.golang/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:593 +0x220
net/http.serverHandler.ServeHTTP(0xc0000b5ee0, 0x1a676c0, 0xc000392000, 0xc00014e300)
	/usr/local/Cellar/go/1.11.5/libexec/src/net/http/server.go:2741 +0xab
net/http.(*conn).serve(0xc000166000, 0x1a685c0, 0xc00013c400)
	/usr/local/Cellar/go/1.11.5/libexec/src/net/http/server.go:1847 +0x646
created by net/http.(*Server).Serve
	/usr/local/Cellar/go/1.11.5/libexec/src/net/http/server.go:2851 +0x2f5

@im-kulikov im-kulikov changed the title Simplify code of Add/Remove trailing slash Simplify code of Add/Remove trailing slash and fix bug Feb 5, 2019
@im-kulikov
Copy link
Contributor Author

im-kulikov commented Feb 5, 2019

I corrected the description. In addition to simplifying and understanding the code, this PR fixes bug in the runtime.

Thoughts @vishr @alexaandru?

@vishr vishr merged commit 8896575 into labstack:master Feb 7, 2019
@im-kulikov im-kulikov deleted the feature/simplify-traling-slash branch February 7, 2019 17:50
@alexaandru
Copy link
Contributor

Nice cleanup! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants