http_core.c revision 73579c435f9f6c2670c4391114368a2eedaf8ebf
127N/A/* ==================================================================== 127N/A * The Apache Software License, Version 1.1 127N/A * Copyright (c) 2000-2001 The Apache Software Foundation. All rights 127N/A * Redistribution and use in source and binary forms, with or without 127N/A * modification, are permitted provided that the following conditions 127N/A * 1. Redistributions of source code must retain the above copyright 127N/A * notice, this list of conditions and the following disclaimer. 127N/A * 2. Redistributions in binary form must reproduce the above copyright 127N/A * notice, this list of conditions and the following disclaimer in 127N/A * the documentation and/or other materials provided with the 127N/A * 3. The end-user documentation included with the redistribution, 127N/A * if any, must include the following acknowledgment: 127N/A * "This product includes software developed by the 127N/A * Alternately, this acknowledgment may appear in the software itself, 127N/A * if and wherever such third-party acknowledgments normally appear. 127N/A * 4. The names "Apache" and "Apache Software Foundation" must 127N/A * not be used to endorse or promote products derived from this 127N/A * software without prior written permission. For written 127N/A * permission, please contact apache@apache.org. 127N/A * 5. Products derived from this software may not be called "Apache", 127N/A * nor may "Apache" appear in their name, without prior written 127N/A * permission of the Apache Software Foundation. 127N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 127N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 127N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 127N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 127N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 127N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 127N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 127N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 127N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 127N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 127N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 127N/A * ==================================================================== 127N/A * This software consists of voluntary contributions made by many 181N/A * individuals on behalf of the Apache Software Foundation. For more 127N/A * information on the Apache Software Foundation, please see * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. /* We've changed it to On/Off, but used to use numbers * so we accept anything but "Off" or "0" as "On" "Keep-Alive timeout duration (sec)"),
"Maximum number of Keep-Alive requests per connection, or 0 for infinite"),
"Whether persistent connections should be On or Off"),
* HTTP/1.1 chunked transfer encoding filter. char chunk_hdr[
20];
/* enough space for the snprintf below */ /* there shouldn't be anything after the eos */ /* unknown amount of data (e.g. a pipe) */ * There may be a new next bucket representing the * rest of the data stream on which a read() may * block so we pass down what we have so far. /* If there was nothing in this bucket then we can * safely move on to the next one without pausing * to pass down what we have counted up so far. * XXX: if there aren't very many bytes at this point it may * be a good idea to set them aside and return for more, * unless we haven't finished counting this brigade yet. /* if there are content bytes, then wrap them in a chunk */ * Insert the chunk header, specifying the number of bytes in /* XXX might be nice to have APR_OFF_T_FMT_HEX */ * Insert the end-of-chunk CRLF before the EOS bucket, or * appended to the brigade /* RFC 2616, Section 3.6.1 * If there is an EOS bucket, then prefix it with: * 1) the last-chunk marker ("0" CRLF) * 3) the end-of-chunked body CRLF * If there is no EOS bucket, then do nothing. * XXX: it would be nice to combine this with the end-of-chunk * marker above, but this is a bit more straight-forward for /* XXX: (2) trailers ... does not yet exist */ /* pass the brigade to the next filter. */ * Read and process each request found on our connection * until no requests are left or we decide to close. /* process the request if it was read without error */ int major =
1,
minor = 0;
/* Assume HTTP/1.0 if non-"HTTP" protocol */ /* Read past empty lines until we get a real request line, * a read error, the connection closes (EOF), or we timeout. * We skip empty lines because browsers have to tack a CRLF on to the end * of POSTs to support old CERN webservers. But note that we may not * have flushed any previous response completely to the client yet. * We delay the flush as long as possible so that we can improve * performance for clients that are pipelining requests. If a request * is pipelined then we won't block during the (implicit) read() below. * If the requests aren't pipelined, then the client is still waiting * for the final buffer flush from us, and we will block in the implicit * read(). B_SAFEREAD ensures that the BUFF layer flushes if it will * have to block during a read. if (
len < 0) {
/* includes EOF */ /* this is a hack to make sure that request time is set, * it's not perfect, but it's better than nothing /* we've probably got something to do, ignore graceful restart requests */ /* XXX - sigwait doesn't work if the signal has been SIG_IGNed (under * linux 2.0 w/ glibc 2.0, anyway), and this step isn't necessary when * we're running a sigwait thread anyway. If/when unthreaded mode is * put back in, we should make sure to ignore this signal iff a sigwait * thread isn't used. - mvsk apr_signal(SIGWINCH, SIG_IGN); /* XXX If we want to keep track of the Method, the protocol module should do * it. That support isn't in the scoreboard yet. Hopefully next week /* Provide quick information about the request method as soon as known */ /* ap_getline returns (size of max buffer - 1) if it fills up the * buffer before finding the end-of-line. This is only going to * happen if it exceeds the configured limit for a request-line. /* XXX ap_update_connection_status(conn->id, "Protocol", r->protocol); */ /* Avoid sscanf in the common case */ pro[0] ==
'H' &&
pro[
1] ==
'T' &&
pro[
2] ==
'T' &&
pro[
3] ==
'P' &&
/* XXX can we optimize these timeouts at all? gstein */ "request failed: URI too long");
NULL,
/* create per-directory config structure */ NULL,
/* merge per-directory config structures */ NULL,
/* create per-server config structure */ NULL,
/* merge per-server config structures */