-: 0:Source:modperl_cgi.c -: 0:Object:modperl_cgi.bb -: 1:/* Copyright 2001-2004 The Apache Software Foundation -: 2: * -: 3: * Licensed under the Apache License, Version 2.0 (the "License"); -: 4: * you may not use this file except in compliance with the License. -: 5: * You may obtain a copy of the License at -: 6: * -: 7: * http://www.apache.org/licenses/LICENSE-2.0 -: 8: * -: 9: * Unless required by applicable law or agreed to in writing, software -: 10: * distributed under the License is distributed on an "AS IS" BASIS, -: 11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 12: * See the License for the specific language governing permissions and -: 13: * limitations under the License. -: 14: */ -: 15: -: 16:#include "mod_perl.h" -: 17: -: 18:MP_INLINE int modperl_cgi_header_parse(request_rec *r, char *buffer, -: 19: int *len, const char **body) 81: 20:{ 81: 21: int status; 81: 22: int termarg; 81: 23: const char *location; 81: 24: const char *tmp; 81: 25: int tlen, newln; -: 26: 81: 27: if (!buffer) { #####: 28: return DECLINED; -: 29: } -: 30: -: 31: /* ap_scan_script_header_err_strs won't handle correctly binary -: 32: * data following the headers, e.g. when the terminating /\n\r?\n/ -: 33: * is followed by \0\0 which is a part of the response -: 34: * body. Therefore we need to separate the headers from the body -: 35: * and not rely on ap_scan_script_header_err_strs to do that for -: 36: * us. -: 37: */ 81: 38: tmp = buffer; 81: 39: newln = 0; 81: 40: tlen = *len; 81: 41: while (tlen--) { -: 42: /* that strange mix of CR and \n (and not LF) copied from -: 43: * util_script.c:ap_scan_script_header_err_core -: 44: */ 3889: 45: if (*tmp != CR && *tmp != '\n') { 3648: 46: newln = 0; -: 47: } 3683: 48: if (*tmp == '\n') { 206: 49: newln++; -: 50: } 3889: 51: tmp++; 3889: 52: if (newln == 2) { 3808: 53: break; -: 54: } -: 55: } -: 56: 81: 57: if (tmp - buffer >= *len) { 32: 58: *body = NULL; /* no body along with headers */ 32: 59: *len = 0; -: 60: } -: 61: else { 49: 62: *body = tmp; 49: 63: *len = *len - (tmp - buffer); -: 64: } -: 65: 81: 66: status = ap_scan_script_header_err_strs(r, NULL, NULL, -: 67: &termarg, buffer, NULL); -: 68: -: 69: /* code below from mod_cgi.c */ 81: 70: location = apr_table_get(r->headers_out, "Location"); -: 71: 81: 72: if (location && (location[0] == '/') && (r->status == 200)) { 1: 73: r->method = apr_pstrdup(r->pool, "GET"); 1: 74: r->method_number = M_GET; -: 75: -: 76: /* We already read the message body (if any), so don't allow -: 77: * the redirected request to think it has one. We can ignore -: 78: * Transfer-Encoding, since we used REQUEST_CHUNKED_ERROR. -: 79: */ 1: 80: apr_table_unset(r->headers_in, "Content-Length"); -: 81: 1: 82: ap_internal_redirect_handler(location, r); -: 83: 1: 84: return OK; -: 85: } 3: 86: else if (location && (r->status == 200)) { 3: 87: MP_dRCFG; -: 88: -: 89: /* Note that if a script wants to produce its own Redirect -: 90: * body, it now has to explicitly *say* "Status: 302" -: 91: */ -: 92: -: 93: /* XXX: this is a hack. -: 94: * filter return value doesn't seem to impact anything. -: 95: */ 3: 96: rcfg->status = HTTP_MOVED_TEMPORARILY; -: 97: 3: 98: return HTTP_MOVED_TEMPORARILY; -: 99: } -: 100: 77: 101: return status; -: 102:}