summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-01 22:50:07 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-01 22:50:07 +0300
commit5fb32fcfca41d2e1b6eaaacaa6b6b37fc9e6d0b1 (patch)
tree2e01c7226a558bb51d8c4e82c46600e57d74f3cb /src/ui/documentwidget.c
parenta05d181c72df33256e603f2e4543ee73665b242c (diff)
Handling status codes by class
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 3b8c468b..c8755fd2 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -419,26 +419,19 @@ static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) {
419 enum iGmStatusCode statusCode = status_GmRequest(d->request); 419 enum iGmStatusCode statusCode = status_GmRequest(d->request);
420 if (d->state == fetching_DocumentState) { 420 if (d->state == fetching_DocumentState) {
421 d->state = receivedPartialResponse_DocumentState; 421 d->state = receivedPartialResponse_DocumentState;
422 switch (statusCode) { 422 switch (statusCode / 10) {
423 case none_GmStatusCode: 423 case 1: /* input required */ {
424 case success_GmStatusCode:
425 d->scrollY = 0;
426 reset_GmDocument(d->doc); /* new content incoming */
427 updateSource_DocumentWidget_(d);
428 break;
429 case input_GmStatusCode:
430 case sensitiveInput_GmStatusCode: {
431 iUrl parts; 424 iUrl parts;
432 init_Url(&parts, d->url); 425 init_Url(&parts, d->url);
426 printf("%s\n", cstr_String(meta_GmRequest(d->request)));
433 iWidget *dlg = makeValueInput_Widget( 427 iWidget *dlg = makeValueInput_Widget(
434 as_Widget(d), 428 as_Widget(d),
435 NULL, 429 NULL,
436 format_CStr(cyan_ColorEscape "%s", 430 format_CStr(cyan_ColorEscape "%s",
437 cstr_String(collect_String(newRange_String(parts.host)))), 431 cstr_String(collect_String(newRange_String(parts.host)))),
438 isEmpty_String(meta_GmRequest(d->request)) 432 isEmpty_String(meta_GmRequest(d->request))
439 ? format_CStr( 433 ? format_CStr("Please enter input for %s:",
440 "Please enter input for %s:", 434 cstr_String(collect_String(newRange_String(parts.path))))
441 cstr_String(collect_String(newRange_String(parts.path))))
442 : cstr_String(meta_GmRequest(d->request)), 435 : cstr_String(meta_GmRequest(d->request)),
443 orange_ColorEscape "Send \u21d2", 436 orange_ColorEscape "Send \u21d2",
444 "document.input.submit"); 437 "document.input.submit");
@@ -446,19 +439,32 @@ static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) {
446 statusCode == sensitiveInput_GmStatusCode); 439 statusCode == sensitiveInput_GmStatusCode);
447 break; 440 break;
448 } 441 }
449 case redirectTemporary_GmStatusCode: 442 case 2: /* success */
450 case redirectPermanent_GmStatusCode: 443 d->scrollY = 0;
444 reset_GmDocument(d->doc); /* new content incoming */
445 updateSource_DocumentWidget_(d);
446 break;
447 case 3: /* redirect */
451 if (isEmpty_String(meta_GmRequest(d->request))) { 448 if (isEmpty_String(meta_GmRequest(d->request))) {
452 showErrorPage_DocumentWidget_(d, invalidRedirect_GmStatusCode); 449 showErrorPage_DocumentWidget_(d, invalidRedirect_GmStatusCode);
453 } 450 }
454 else { 451 else {
455 postCommandf_App("open redirect:1 url:%s", 452 postCommandf_App(
456 cstr_String(meta_GmRequest(d->request))); 453 "open redirect:1 url:%s",
454 cstr_String(absoluteUrl_String(d->url, meta_GmRequest(d->request))));
457 iReleasePtr(&d->request); 455 iReleasePtr(&d->request);
458 } 456 }
459 break; 457 break;
460 default: 458 default:
461 showErrorPage_DocumentWidget_(d, statusCode); 459 if (isDefined_GmError(statusCode)) {
460 showErrorPage_DocumentWidget_(d, statusCode);
461 }
462 else if (statusCode / 10 == 4) {
463 showErrorPage_DocumentWidget_(d, temporaryFailure_GmStatusCode);
464 }
465 else if (statusCode / 10 == 5) {
466 showErrorPage_DocumentWidget_(d, permanentFailure_GmStatusCode);
467 }
462 break; 468 break;
463 } 469 }
464 } 470 }