Skip to content

http > https redirect #860

@maxvoronov

Description

@maxvoronov

Description

I have a problem with redirect from http to https. In logs I see error:

http: TLS handshake error from 172.21.0.1:37412: tls: first record does not look like a TLS handshake

Used middleware: HTTPSRedirect.
I'm not sure that is bug. But I don't know how to fix it. Can you advice?

Checklist

  • [+] Dependencies installed
  • [+] No typos
  • [+] Searched existing issues and docs

Expected behaviour

No redirect, incorrect response in browser and error in logs.

Actual behaviour

Redirect from http://localhost:8080/ to https://localhost:8080/.

Steps to reproduce

Start server and open url http://localhost:8080/

Working code to debug

package main

import (
	"github.com/labstack/echo"
	"github.com/labstack/echo/middleware"
	"net/http"
)

func indexHandler(c echo.Context) error {
	return c.JSON(http.StatusOK, "OK")
}

func main() {
	api := echo.New()
	api.Pre(middleware.HTTPSRedirect())
	api.Use(middleware.Logger())
	api.Use(middleware.Recover())

	api.GET("/", indexHandler)
	api.Logger.Fatal(api.StartTLS(":8080", "/opt/cert/cert.pem", "/opt/cert/key.pem"))
}

Version/commit

echo v3.0.3 (commit 8d504c1)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions