Skip to content

Commit c544ee3

Browse files
committed
fix nb
1 parent 7194a52 commit c544ee3

File tree

2 files changed

+49
-33
lines changed

2 files changed

+49
-33
lines changed

fasthtml/oauth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ def get_host(request):
127127
return forwarded_host if forwarded_host else request.url.netloc
128128

129129
# %% ../nbs/api/08_oauth.ipynb
130-
def redir_url(request, redir_path, scheme=None):
130+
def redir_url(req, redir_path, scheme=None):
131131
"Get the redir url for the host in `request`"
132-
host = get_host(request)
133-
scheme = 'http' if url_match(req,self.http_patterns) or not self.https else 'https'
132+
host = get_host(req)
133+
scheme = 'http' if host.split(':')[0] in ("localhost", "127.0.0.1") else 'https'
134134
return f"{scheme}://{host}{redir_path}"
135135

136136
# %% ../nbs/api/08_oauth.ipynb

nbs/api/08_oauth.ipynb

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -352,40 +352,13 @@
352352
"outputs": [],
353353
"source": [
354354
"#| export\n",
355-
"def redir_url(request, redir_path, scheme=None):\n",
355+
"def redir_url(req, redir_path, scheme=None):\n",
356356
" \"Get the redir url for the host in `request`\"\n",
357-
" host = get_host(request)\n",
358-
" scheme = 'http' if url_match(req,self.http_patterns) or not self.https else 'https'\n",
357+
" host = get_host(req)\n",
358+
" scheme = 'http' if host.split(':')[0] in (\"localhost\", \"127.0.0.1\") else 'https'\n",
359359
" return f\"{scheme}://{host}{redir_path}\""
360360
]
361361
},
362-
{
363-
"cell_type": "code",
364-
"execution_count": null,
365-
"id": "fee2db6c",
366-
"metadata": {},
367-
"outputs": [
368-
{
369-
"name": "stdout",
370-
"output_type": "stream",
371-
"text": [
372-
"Localhost: http://localhost:8000/redirect\n",
373-
"With X-Forwarded-Host: https://example.com/redirect\n",
374-
"Production: https://myapp.com/redirect\n"
375-
]
376-
}
377-
],
378-
"source": [
379-
"from types import SimpleNamespace\n",
380-
"from urllib.parse import urlparse\n",
381-
"\n",
382-
"mock_request_prod = SimpleNamespace(headers={}, url=SimpleNamespace(netloc='myapp.com', hostname='myapp.com'))\n",
383-
"\n",
384-
"print(\"Localhost:\", redir_url(mock_request_localhost, '/redirect'))\n",
385-
"print(\"With X-Forwarded-Host:\", redir_url(mock_request_with_forward, '/redirect'))\n",
386-
"print(\"Production:\", redir_url(mock_request_prod, '/redirect'))"
387-
]
388-
},
389362
{
390363
"cell_type": "code",
391364
"execution_count": null,
@@ -522,6 +495,33 @@
522495
" return any(re.match(pattern, get_host(request).split(':')[0]) for pattern in patterns)"
523496
]
524497
},
498+
{
499+
"cell_type": "code",
500+
"execution_count": null,
501+
"id": "fee2db6c",
502+
"metadata": {},
503+
"outputs": [
504+
{
505+
"name": "stdout",
506+
"output_type": "stream",
507+
"text": [
508+
"Localhost: http://localhost:8000/redirect\n",
509+
"With X-Forwarded-Host: https://example.com/redirect\n",
510+
"Production: https://myapp.com/redirect\n"
511+
]
512+
}
513+
],
514+
"source": [
515+
"from types import SimpleNamespace\n",
516+
"from urllib.parse import urlparse\n",
517+
"\n",
518+
"mock_request_prod = SimpleNamespace(headers={}, url=SimpleNamespace(netloc='myapp.com', hostname='myapp.com'))\n",
519+
"\n",
520+
"print(\"Localhost:\", redir_url(mock_request_localhost, '/redirect'))\n",
521+
"print(\"With X-Forwarded-Host:\", redir_url(mock_request_with_forward, '/redirect'))\n",
522+
"print(\"Production:\", redir_url(mock_request_prod, '/redirect'))"
523+
]
524+
},
525525
{
526526
"cell_type": "code",
527527
"execution_count": null,
@@ -622,6 +622,8 @@
622622
"text/markdown": [
623623
"---\n",
624624
"\n",
625+
"[source](https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L223){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
626+
"\n",
625627
"### GoogleAppClient.consent_url\n",
626628
"\n",
627629
"> GoogleAppClient.consent_url (proj=None)\n",
@@ -631,6 +633,8 @@
631633
"text/plain": [
632634
"---\n",
633635
"\n",
636+
"[source](https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L223){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
637+
"\n",
634638
"### GoogleAppClient.consent_url\n",
635639
"\n",
636640
"> GoogleAppClient.consent_url (proj=None)\n",
@@ -673,6 +677,8 @@
673677
"text/markdown": [
674678
"---\n",
675679
"\n",
680+
"[source](https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L231){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
681+
"\n",
676682
"### Credentials.update\n",
677683
"\n",
678684
"> Credentials.update ()\n",
@@ -682,6 +688,8 @@
682688
"text/plain": [
683689
"---\n",
684690
"\n",
691+
"[source](https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L231){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
692+
"\n",
685693
"### Credentials.update\n",
686694
"\n",
687695
"> Credentials.update ()\n",
@@ -723,6 +731,8 @@
723731
"text/markdown": [
724732
"---\n",
725733
"\n",
734+
"[source](https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L238){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
735+
"\n",
726736
"### Credentials.save\n",
727737
"\n",
728738
"> Credentials.save (fname)\n",
@@ -732,6 +742,8 @@
732742
"text/plain": [
733743
"---\n",
734744
"\n",
745+
"[source](https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L238){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
746+
"\n",
735747
"### Credentials.save\n",
736748
"\n",
737749
"> Credentials.save (fname)\n",
@@ -788,6 +800,8 @@
788800
"text/markdown": [
789801
"---\n",
790802
"\n",
803+
"[source](https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L249){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
804+
"\n",
791805
"### GoogleAppClient.creds\n",
792806
"\n",
793807
"> GoogleAppClient.creds ()\n",
@@ -797,6 +811,8 @@
797811
"text/plain": [
798812
"---\n",
799813
"\n",
814+
"[source](https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L249){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
815+
"\n",
800816
"### GoogleAppClient.creds\n",
801817
"\n",
802818
"> GoogleAppClient.creds ()\n",

0 commit comments

Comments
 (0)