Skip to content

net/http: *Request.URL.Scheme returns an empty string. #57533

@li-jin-gou

Description

@li-jin-gou

What version of Go are you using (go version)?

$ go version
go version go1.19.2 darwin/amd64

Does this issue reproduce with the latest release?

package main

import (
	"github.com/gin-gonic/gin"
)

func main() {
	g := gin.Default()
	g.GET("/ping", func(c *gin.Context) {
		// Request   *http.Request
                // c.Request.URL.Scheme return an empty string instead of http.
		c.String(200, "Hello %s", c.Request.URL.Scheme)
	})
	g.Run(":8080")
}

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

I was using gin and found that http.Request.URL.Scheme was equal to "". Is this a normal behaviour?

I see this issue #28940 mentions a similar problem, and I'd like to make sure that the return of an empty string is the same for all go versions? And are there any plans to change it in Go2 in the future?

What did you expect to see?

Many people think that Schema will return the Http/https 's schema but it is empty, is there any other way to replace it?

Best wish💕

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions