diff options
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 43b1664f..7f76a436 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -503,23 +503,27 @@ static void setSource_DocumentWidget_(iDocumentWidget *d, const iString *source) | |||
503 | refresh_Widget(as_Widget(d)); | 503 | refresh_Widget(as_Widget(d)); |
504 | } | 504 | } |
505 | 505 | ||
506 | static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode code) { | 506 | static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode code, |
507 | const iString *meta) { | ||
507 | iString *src = collectNewCStr_String("# "); | 508 | iString *src = collectNewCStr_String("# "); |
508 | const iGmError *msg = get_GmError(code); | 509 | const iGmError *msg = get_GmError(code); |
509 | appendChar_String(src, msg->icon ? msg->icon : 0x2327); /* X in a box */ | 510 | appendChar_String(src, msg->icon ? msg->icon : 0x2327); /* X in a box */ |
510 | appendFormat_String(src, " %s\n%s", msg->title, msg->info); | 511 | appendFormat_String(src, " %s\n%s", msg->title, msg->info); |
511 | if (d->request) { | 512 | if (meta) { |
512 | switch (code) { | 513 | switch (code) { |
514 | case nonGeminiRedirect_GmStatusCode: | ||
515 | appendFormat_String(src, "\n=> %s\n", cstr_String(meta)); | ||
516 | break; | ||
513 | case failedToOpenFile_GmStatusCode: | 517 | case failedToOpenFile_GmStatusCode: |
514 | case certificateNotValid_GmStatusCode: | 518 | case certificateNotValid_GmStatusCode: |
515 | appendFormat_String(src, "\n\n%s", cstr_String(meta_GmRequest(d->request))); | 519 | appendFormat_String(src, "\n\n%s", cstr_String(meta)); |
516 | break; | 520 | break; |
517 | case unsupportedMimeType_GmStatusCode: | 521 | case unsupportedMimeType_GmStatusCode: |
518 | appendFormat_String(src, "\n```\n%s\n```\n", cstr_String(meta_GmRequest(d->request))); | 522 | appendFormat_String(src, "\n```\n%s\n```\n", cstr_String(meta)); |
519 | break; | 523 | break; |
520 | case slowDown_GmStatusCode: | 524 | case slowDown_GmStatusCode: |
521 | appendFormat_String(src, "\n\nWait %s seconds before your next request.", | 525 | appendFormat_String(src, "\n\nWait %s seconds before your next request.", |
522 | cstr_String(meta_GmRequest(d->request))); | 526 | cstr_String(meta)); |
523 | break; | 527 | break; |
524 | default: | 528 | default: |
525 | break; | 529 | break; |
@@ -599,7 +603,7 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse | |||
599 | } | 603 | } |
600 | } | 604 | } |
601 | if (docFormat == undefined_GmDocumentFormat) { | 605 | if (docFormat == undefined_GmDocumentFormat) { |
602 | showErrorPage_DocumentWidget_(d, unsupportedMimeType_GmStatusCode); | 606 | showErrorPage_DocumentWidget_(d, unsupportedMimeType_GmStatusCode, &response->meta); |
603 | deinit_String(&str); | 607 | deinit_String(&str); |
604 | return; | 608 | return; |
605 | } | 609 | } |
@@ -840,27 +844,33 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) { | |||
840 | break; | 844 | break; |
841 | case categoryRedirect_GmStatusCode: | 845 | case categoryRedirect_GmStatusCode: |
842 | if (isEmpty_String(meta_GmRequest(d->request))) { | 846 | if (isEmpty_String(meta_GmRequest(d->request))) { |
843 | showErrorPage_DocumentWidget_(d, invalidRedirect_GmStatusCode); | 847 | showErrorPage_DocumentWidget_(d, invalidRedirect_GmStatusCode, NULL); |
844 | } | 848 | } |
845 | else { | 849 | else { |
846 | /* TODO: only accept redirects that use gemini scheme */ | 850 | /* Only accept redirects that use gemini scheme. */ |
847 | postCommandf_App( | 851 | const iString *dstUrl = absoluteUrl_String(d->mod.url, meta_GmRequest(d->request)); |
848 | "open redirect:1 url:%s", | 852 | if (equalCase_Rangecc(urlScheme_String(dstUrl), "gemini")) { |
849 | cstr_String(absoluteUrl_String(d->mod.url, meta_GmRequest(d->request)))); | 853 | postCommandf_App("open redirect:1 url:%s", cstr_String(dstUrl)); |
854 | } | ||
855 | else { | ||
856 | showErrorPage_DocumentWidget_(d, nonGeminiRedirect_GmStatusCode, dstUrl); | ||
857 | } | ||
850 | iReleasePtr(&d->request); | 858 | iReleasePtr(&d->request); |
851 | } | 859 | } |
852 | break; | 860 | break; |
853 | default: | 861 | default: |
854 | if (isDefined_GmError(statusCode)) { | 862 | if (isDefined_GmError(statusCode)) { |
855 | showErrorPage_DocumentWidget_(d, statusCode); | 863 | showErrorPage_DocumentWidget_(d, statusCode, meta_GmRequest(d->request)); |
856 | } | 864 | } |
857 | else if (category_GmStatusCode(statusCode) == | 865 | else if (category_GmStatusCode(statusCode) == |
858 | categoryTemporaryFailure_GmStatusCode) { | 866 | categoryTemporaryFailure_GmStatusCode) { |
859 | showErrorPage_DocumentWidget_(d, temporaryFailure_GmStatusCode); | 867 | showErrorPage_DocumentWidget_( |
868 | d, temporaryFailure_GmStatusCode, meta_GmRequest(d->request)); | ||
860 | } | 869 | } |
861 | else if (category_GmStatusCode(statusCode) == | 870 | else if (category_GmStatusCode(statusCode) == |
862 | categoryPermanentFailure_GmStatusCode) { | 871 | categoryPermanentFailure_GmStatusCode) { |
863 | showErrorPage_DocumentWidget_(d, permanentFailure_GmStatusCode); | 872 | showErrorPage_DocumentWidget_( |
873 | d, permanentFailure_GmStatusCode, meta_GmRequest(d->request)); | ||
864 | } | 874 | } |
865 | break; | 875 | break; |
866 | } | 876 | } |