#How to make request.url_for() return HTTPS URI

1 messages · Page 1 of 1 (latest)

nova sedge
#

I'm calling but I get an HTTP URI back. Is there a way to make it return HTTPS?

redirect_uri = request.url_for("github_callback")
nova sedge
#

It seems that its obtained from scope["scheme"] but defaults to http

#

What would be the best way to set scope["scheme"] = 'https' during app startup

nova sedge
#

@warm sparrow any chance you've come by this before?

warm sparrow
#

hmm, i'm looking in the test cases and we do have checks for that. Let me dig a little more to see how to set or override it

warm sparrow
#

(i didn't mean that rudely at all)

nova sedge
nova sedge
warm sparrow
#

ok, so in cloud run, you aren't running encrypted

#

it's a requirement, i think

#

it's encrypted on the other side

#

from the proxy on

#

but, you do have an https endpoint

nova sedge
#

cloud run provisions an https endpoint to access

#

but i think you are right, from the app perspective its not running https

#

the cloud run proxy that points to my app is

#

but the litestar app itself isn't aware of that i guess

warm sparrow
#

ok, cool. I think we are on the same page. I guess I'd have this issue too since i use cloud run

#

well, a quick fix for now would be to just .replace('http:','https:') to the end

nova sedge
#

yup thats exactly what i did

#

meanwhile

warm sparrow
#

but i think the proxy headers are probably there

#

are you able to see if there's anything in the headers that has the referring address/url?

#

maybe like an X-Forwarded-For or something similar

#

I can do the same, but i have IAP sitting in front

#

so i don't know if that changes things

nova sedge
#

in my case its just /v1/oauth2/github/login that returns a redirect to the URL construct from url_for()

#

no forwarded header

warm sparrow
#

ok, let me look at look to see if i can find anything from our docs

#

and you have the run/invoke allowed for all in on the cloud run service?

nova sedge
#

this probably does not need that much attention, but it would be nice to be able to override scheme for url_for() like Flask

#

I can create an issue for it

#

If it makes sense to you

#

And perhaps later it can be done

warm sparrow
#

please do.

nova sedge
#

For now I'm totally fine replacing

warm sparrow
#

does url_for always return a fully qualified URL?

nova sedge
#

afaik yes

warm sparrow
#

this is not a feature I actually use currently (too many things to changing at a time!)

#

ok, it might be good to have a relative flag to pass in

#

and a scheme override

nova sedge
#

yep

#

in Q1 2024 i probably start contributing more

#

right now rushing a product lol

warm sparrow
#

whenever you are ready.

nova sedge
#

🫡

warm sparrow
#

what are you using for the UI in your product?

#

I think that's something I'd like to address soon

nova sedge
#

react but i don't do the frontend side

#

i had been working with Go the past year so I'm not really familiar python stack

#

but I like litestar and how everyone is contributing

#

strong