Gin: why Request.URL, Host & Scheme are empty?

Created on 21 Jan 2018  Â·  7Comments  Â·  Source: gin-gonic/gin

Hi

I build gin & use curl to request api

use "github.com/happierall/l" to make the log pretty

use l.Log(c.Request.URL) and the log are below

c is c *gin.Context

    URL:    &url.URL{
        Scheme:     "",
        Opaque:     "",
        User:       (*url.Userinfo)(nil),
        Host:       "",
        Path:       "/v1/playback/demo/videmo/id123/1516375842496",
        RawPath:    "",
        ForceQuery: false,
        RawQuery:   "",
        Fragment:   "",
    },

why Host & Scheme are empty?

Most helpful comment

because your RequestURI is relative.

so how can i get the absolute_uri?

All 7 comments

because your RequestURI is relative.

because your RequestURI is relative.

what does that mean?

because your RequestURI is relative.

so how can i get the absolute_uri?

hello,

Why the url struct from *gin.context request is empty in localhost ??

I'm accessing this url in my server: http://local.mininoticias.com.ar:8084/

If I print

fmt.Println("request url:", c.Request.URL)
fmt.Println("request host:", c.Request.Host)

I get:

request url: /
request host: local.mininoticias.com.ar:8084

So no host, scheme or anything in the url struct

Not sure why this issue was closed without any explanation

I'd love to have an answer as well. At least c.Request.Host seems to be correct, but I just have to guess the Scheme. And yes, the call was a relative URI — so what?

Ok, it seems that this was closed because it's not an issue with Gin, but with the weird way the underlying http library works: https://stackoverflow.com/questions/6899069/why-are-request-url-host-and-scheme-blank-in-the-development-server

The comments there give some ideas on how to extract the relevant data _if_ the call is a relative call...

I guess that's why this issue was closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iiinsomnia picture iiinsomnia  Â·  3Comments

cxk280 picture cxk280  Â·  3Comments

ghost picture ghost  Â·  3Comments

nxvl picture nxvl  Â·  3Comments

Bloomca picture Bloomca  Â·  3Comments