How to get request url scheme?

358 views
Skip to first unread message

Anik Hasibul

unread,
Nov 24, 2018, 10:21:01 PM11/24/18
to golang-nuts
Hi there!
I am working on a web application. And I need to get the scheme of the request url.
I tried `req.URL.Scheme` it returned empty string.
But my expectation was `http` or `https`

Any idea to get that?

Robert Engels

unread,
Nov 24, 2018, 11:21:06 PM11/24/18
to Anik Hasibul, golang-nuts
That should be it... file a bug
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Anik Hasibul

unread,
Nov 25, 2018, 2:19:30 AM11/25/18
to Robert Engels, golang-nuts
Thank you so much. I thought I did something wrong. But Now I am pretty sure that it's a bug.

Issue opened on GitHub!

Hasibul Hasan (Anik)  

Mobile: +8801902566424
Email  : anikh...@outlook.com
Github: @AnikHasibul
Medium: @AnikHasibul


From: Robert Engels <ren...@ix.netcom.com>
Sent: Sunday, November 25, 2018 10:20:46 AM
To: Anik Hasibul
Cc: golang-nuts
Subject: Re: [go-nuts] How to get request url scheme?
 

robert engels

unread,
Nov 25, 2018, 3:13:45 AM11/25/18
to Anik Hasibul, golang-nuts
Technically, the Scheme is optional, but if your url has it, it should be parsed into that field.

Tristan Colgate

unread,
Nov 25, 2018, 4:11:03 AM11/25/18
to robert engels, Anik Hasibul, golang-nuts
On the server side you don't know the scheme used. It isn't part of the request as such. It has to be determined based on the properties of the port that got the request (if you are listening with TLS on a port, the request you got is definitely some flavour of https).
  If you have a reverse proxy, or load balancer in front of your app it maybe get passed the scheme in a header (x-forwarded-proto IIRC)
Reply all
Reply to author
Forward
0 new messages