how do you get the original request protocol?

619 views
Skip to first unread message

deitch

unread,
Dec 8, 2011, 5:03:07 PM12/8/11
to Express
If you want to know the URL that was used to request you, in a
particular route, you can use:

req.headers.host - the host and port
req.url - the entire path
req.method - PUT/GET/POST/etc.

But how do you get the protocol part of the URL?

kapouer

unread,
Feb 2, 2012, 12:31:14 PM2/2/12
to Express
Hi,
an answer at :
http://groups.google.com/group/express-js/browse_thread/thread/b0b51f7ca1090859/8a364687e0ffeca8

req.connection.encrypted ? 'https' : 'http'

If i want to populate my <base> tag, i must prepare that local
variable :
(req.connection.encrypted ? 'https' : 'http') + '://' +
req.header('host') + (req.app.settings.basepath || '')

ugly !

vision media [ Tj Holowaychuk ]

unread,
Feb 7, 2012, 7:23:18 AM2/7/12
to expre...@googlegroups.com
we already reconstruct it in res.redirect(), I could expose it as req.<something>. 


--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.




--
Tj Holowaychuk
Vision Media
President & Creative Lead

Avi Deitcher

unread,
Feb 7, 2012, 7:25:56 AM2/7/12
to expre...@googlegroups.com
That would be pretty good. I already worked around it, but sometimes it is good to have it.

Jérémy Lal

unread,
Feb 7, 2012, 9:09:44 AM2/7/12
to expre...@googlegroups.com
If express call url.parse() the result could be accessible in req.url,
that would give all information we need in one place, in a standard manner.

J�r�my.

PS: expressjs is wonderful :)

On 07/02/2012 13:23, vision media [ Tj Holowaychuk ] wrote:
> we already reconstruct it in res.redirect(), I could expose it as req.<something>.
>

> On Thu, Feb 2, 2012 at 9:31 AM, kapouer <hol...@gmail.com <mailto:hol...@gmail.com>> wrote:
>
> Hi,
> an answer at :
> http://groups.google.com/group/express-js/browse_thread/thread/b0b51f7ca1090859/8a364687e0ffeca8
>
> req.connection.encrypted ? 'https' : 'http'
>
> If i want to populate my <base> tag, i must prepare that local
> variable :
> (req.connection.encrypted ? 'https' : 'http') + '://' +
> req.header('host') + (req.app.settings.basepath || '')
>
> ugly !
>
> --
> You received this message because you are subscribed to the Google Groups "Express" group.

> To post to this group, send email to expre...@googlegroups.com <mailto:expre...@googlegroups.com>.
> To unsubscribe from this group, send email to express-js+...@googlegroups.com <mailto:express-js%2Bunsu...@googlegroups.com>.

Reply all
Reply to author
Forward
0 new messages