src/server/daemon/error.c

changeset 477
39ebd50cfc12
parent 415
d938228c382e
equal deleted inserted replaced
476:477cbeec7b0b 477:39ebd50cfc12
44 static cxmutstr error_std = ERRMSG("<html><body>error</body></html>"); 44 static cxmutstr 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 cxmutstr msg; 48 cxmutstr msg;
49 if(status < 400) { 49 if(status <= 0) {
50 status = 500;
51 msg = error_500;
52 } else if(status < 400) {
50 msg.ptr = NULL; 53 msg.ptr = NULL;
51 msg.length = 0; 54 msg.length = 0;
52 } else { 55 } else {
53 switch(status) { 56 switch(status) {
54 default: msg = error_std; 57 default: msg = error_std;
70 pblock_removekey(pb_key_content_type, rq->srvhdrs); 73 pblock_removekey(pb_key_content_type, rq->srvhdrs);
71 pblock_removekey(pb_key_content_length, rq->srvhdrs); 74 pblock_removekey(pb_key_content_length, rq->srvhdrs);
72 75
73 pblock_kninsert(pb_key_content_length, msg.length, rq->srvhdrs); 76 pblock_kninsert(pb_key_content_length, msg.length, rq->srvhdrs);
74 pblock_nvinsert("content-type", "text/html", rq->srvhdrs); 77 pblock_nvinsert("content-type", "text/html", rq->srvhdrs);
78 protocol_status(sn, rq, status, NULL);
75 http_start_response(sn, rq); 79 http_start_response(sn, rq);
76 80
77 if(msg.length > 0) { 81 if(msg.length > 0) {
78 net_write(sn->csd, msg.ptr, msg.length); 82 net_write(sn->csd, msg.ptr, msg.length);
79 } 83 }

mercurial