src/server/daemon/error.c

changeset 137
ca0cf1016a8b
parent 132
e9afb5387007
child 195
d367b687bc74
equal deleted inserted replaced
136:9b48a1427aef 137:ca0cf1016a8b
43 43
44 static sstr_t error_std = ERRMSG("<html><body>error</body></html>"); 44 static sstr_t error_std = ERRMSG("<html><body>error</body></html>");
45 45
46 int nsapi_error_request(Session *sn, Request *rq) { 46 int nsapi_error_request(Session *sn, Request *rq) {
47 short status = rq->status_num; 47 short status = rq->status_num;
48 sstr_t msg = error_std; 48 sstr_t msg;
49 switch(status) { 49 if(status < 400) {
50 case 403: { 50 msg.ptr = NULL;
51 msg = error_403; 51 msg.length = 0;
52 break; 52 } else {
53 } 53 switch(status) {
54 case 404: { 54 default: msg = error_std;
55 msg = error_404; 55 case 403: {
56 break; 56 msg = error_403;
57 } 57 break;
58 case 500: { 58 }
59 msg = error_500; 59 case 404: {
60 break; 60 msg = error_404;
61 break;
62 }
63 case 500: {
64 msg = error_500;
65 break;
66 }
61 } 67 }
62 } 68 }
63 69
64 pblock_removekey(pb_key_content_type, rq->srvhdrs); 70 pblock_removekey(pb_key_content_type, rq->srvhdrs);
65 pblock_removekey(pb_key_content_length, rq->srvhdrs); 71 pblock_removekey(pb_key_content_length, rq->srvhdrs);
66 72
67 pblock_kninsert(pb_key_content_length, msg.length, rq->srvhdrs); 73 pblock_kninsert(pb_key_content_length, msg.length, rq->srvhdrs);
68 pblock_nvinsert("content-type", "text/html", rq->srvhdrs); 74 pblock_nvinsert("content-type", "text/html", rq->srvhdrs);
69 http_start_response(sn, rq); 75 http_start_response(sn, rq);
70 76
71 net_write(sn->csd, msg.ptr, msg.length); 77 if(msg.length > 0) {
78 net_write(sn->csd, msg.ptr, msg.length);
79 }
72 80
73 return REQ_PROCEED; 81 return REQ_PROCEED;
74 } 82 }
75 83
76 void fatal_error(HTTPRequest *req, int status) { 84 void fatal_error(HTTPRequest *req, int status) {

mercurial