diff -r 9c639e4941cf -r 85985e88f63b src/server/safs/cgi.c --- a/src/server/safs/cgi.c Sat Oct 29 20:33:46 2016 +0200 +++ b/src/server/safs/cgi.c Sat Oct 29 21:04:10 2016 +0200 @@ -84,6 +84,8 @@ return ret; } + util_env_free(env); + char buf[4096]; // I/O buffer ssize_t r; @@ -111,11 +113,15 @@ int ret = cgi_parse_response(parser, buf, r, &pos); if(ret == -1) { protocol_status(sn, rq, 500, NULL); + cgi_parser_free(parser); return REQ_ABORTED; } else if(ret == 0) { } else if(ret == 1) { cgiheader = FALSE; + if(parser->status > 0) { + protocol_status(sn, rq, parser->status, parser->msg); + } http_start_response(sn, rq); if(pos < r) { net_write(sn->csd, buf+pos, r-pos); @@ -126,6 +132,7 @@ } } + cgi_parser_free(parser); return REQ_PROCEED; } @@ -188,9 +195,18 @@ parser->sn = sn; parser->rq = rq; parser->tmp = ucx_buffer_new(NULL, 64, UCX_BUFFER_AUTOEXTEND); + parser->status = 0; + parser->msg = NULL; return parser; } +void cgi_parser_free(CGIResponseParser *parser) { + if(parser->tmp) { + ucx_buffer_free(parser->tmp); + } + pool_free(parser->sn->pool, parser); +} + /* * parses a cgi response line and adds the response header to rq->srvhdrs * returns 0: incomplete line @@ -229,12 +245,37 @@ if(name.length == 0 || value.length == 0) { return -1; } - pblock_nvlinsert( - name.ptr, - name.length, - value.ptr, - value.length, - parser->rq->srvhdrs); + + if(!sstrcmp(name, S("status"))) { + sstr_t codestr = value; + int i; + for(i=0;i 2) { + break; + } + } + codestr.ptr[i] = '\0'; + + int64_t s = 0; + util_strtoint(codestr.ptr, &s); + parser->status = (int)s; + + sstr_t msg = sstrtrim(sstrsubs(value, i + 1)); + + if(msg.length > 0) { + parser->msg = sstrdup_pool(parser->sn->pool, msg).ptr; + } + } else { + pblock_nvlinsert( + name.ptr, + name.length, + value.ptr, + value.length, + parser->rq->srvhdrs); + } line_begin = i+1; value_begin = line_begin;