|
352 | 352 | "outputs": [],
|
353 | 353 | "source": [
|
354 | 354 | "#| export\n",
|
355 |
| - "def redir_url(request, redir_path, scheme=None):\n", |
| 355 | + "def redir_url(req, redir_path, scheme=None):\n", |
356 | 356 | " \"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", |
359 | 359 | " return f\"{scheme}://{host}{redir_path}\""
|
360 | 360 | ]
|
361 | 361 | },
|
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 |
| - }, |
389 | 362 | {
|
390 | 363 | "cell_type": "code",
|
391 | 364 | "execution_count": null,
|
|
522 | 495 | " return any(re.match(pattern, get_host(request).split(':')[0]) for pattern in patterns)"
|
523 | 496 | ]
|
524 | 497 | },
|
| 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 | + }, |
525 | 525 | {
|
526 | 526 | "cell_type": "code",
|
527 | 527 | "execution_count": null,
|
|
622 | 622 | "text/markdown": [
|
623 | 623 | "---\n",
|
624 | 624 | "\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", |
625 | 627 | "### GoogleAppClient.consent_url\n",
|
626 | 628 | "\n",
|
627 | 629 | "> GoogleAppClient.consent_url (proj=None)\n",
|
|
631 | 633 | "text/plain": [
|
632 | 634 | "---\n",
|
633 | 635 | "\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", |
634 | 638 | "### GoogleAppClient.consent_url\n",
|
635 | 639 | "\n",
|
636 | 640 | "> GoogleAppClient.consent_url (proj=None)\n",
|
|
673 | 677 | "text/markdown": [
|
674 | 678 | "---\n",
|
675 | 679 | "\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", |
676 | 682 | "### Credentials.update\n",
|
677 | 683 | "\n",
|
678 | 684 | "> Credentials.update ()\n",
|
|
682 | 688 | "text/plain": [
|
683 | 689 | "---\n",
|
684 | 690 | "\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", |
685 | 693 | "### Credentials.update\n",
|
686 | 694 | "\n",
|
687 | 695 | "> Credentials.update ()\n",
|
|
723 | 731 | "text/markdown": [
|
724 | 732 | "---\n",
|
725 | 733 | "\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", |
726 | 736 | "### Credentials.save\n",
|
727 | 737 | "\n",
|
728 | 738 | "> Credentials.save (fname)\n",
|
|
732 | 742 | "text/plain": [
|
733 | 743 | "---\n",
|
734 | 744 | "\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", |
735 | 747 | "### Credentials.save\n",
|
736 | 748 | "\n",
|
737 | 749 | "> Credentials.save (fname)\n",
|
|
788 | 800 | "text/markdown": [
|
789 | 801 | "---\n",
|
790 | 802 | "\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", |
791 | 805 | "### GoogleAppClient.creds\n",
|
792 | 806 | "\n",
|
793 | 807 | "> GoogleAppClient.creds ()\n",
|
|
797 | 811 | "text/plain": [
|
798 | 812 | "---\n",
|
799 | 813 | "\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", |
800 | 816 | "### GoogleAppClient.creds\n",
|
801 | 817 | "\n",
|
802 | 818 | "> GoogleAppClient.creds ()\n",
|
|
0 commit comments