http_protocol.c revision 321f97740766bd0accb8ad67a6423ab0e10b8574
* 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * 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. * Code originally by Rob McCool; much redone by Robert S. Thau * and the Apache Software Foundation. #
include "http_log.h" /* For errors detected in basic auth common#
include "util_date.h" /* For parseHTTPdate and BAD_DATE *//* if this is the first error, then log an INFO message and shut down the "client stopped connection before %s completed",
* Builds the content-type that should be sent to the client from the * content-type specified. The following rules are followed: * - if type is NULL, type is set to ap_default_type(r) * - if charset adding is disabled, stop processing and return type. * - then, if there are no parameters on type, add the default charset /* already has parameter, do nothing */ /* XXX we don't check the validity */ /* see if it makes sense to add the charset. At present, * we only add it if the Content-type is one of needcset[] /* Check for Range request-header (HTTP/1.1) or Request-Range for * byte-ranges (e.g. Netscape Navigator 2-3). * We support this form, with Request-Range, and (farther down) we * Request-Range based requests to work around a bug in Netscape * Navigator 2-3 and MSIE 3. /* Check the If-Range header for Etag or Date. * Note that this check will return false (as required) if either * of the two etags are weak. /* If this function is called with realreq=1, it will spit out * the correct headers for a byterange chunk, and set offset and * length to the positions they should be. * If it is called with realreq=0, it will add to tlength the length * it *would* have used with realreq=1. * Either case will return 1 if it should be called again, and 0 /* determine current translation handle, set to the one for * protocol strings, and reset to original setting before /* ### this isn't "content" so we can't use ap_rvputs(), but * ### it should be processed by non-processing filters. We * ### have no "in-between" APIs yet, so send it to the CRLF "Content-range: bytes ",
ts,
/* Translation is not single-byte-only, so we don't know the * content length. Zap the Content-Length header before the * following logic, as the absence of the Content-Length header * may affect the decision on chunked encoding. #
endif /* APACHE_XLATE */ /* The following convoluted conditional determines whether or not * the current connection should remain persistent after this response * (a.k.a. HTTP Keep-Alive) and whether or not the output message * body should use the HTTP/1.1 chunked transfer-coding. In English, * IF we have not marked this connection as errored; * and the response body has a defined length due to the status code * being 304 or 204, the request method being HEAD, already * having defined Content-Length or Transfer-Encoding: chunked, or * the request version being HTTP/1.1 and thus capable of being set * as chunked [we know the (r->chunked = 1) side-effect is ugly]; * and the server configuration enables keep-alive; * and the server configuration has a reasonable inter-request timeout; * and there is no maximum # requests or the max hasn't been reached; * and the response status does not require a close; * and the response generator has not already indicated close; * and the client did not request non-persistence (Connection: close); * and we haven't been configured to ignore the buggy twit * or they're a buggy twit coming through a HTTP/1.1 proxy * and the client is requesting an HTTP/1.0-style keep-alive * or the client claims to be HTTP/1.1 compliant (perhaps a proxy); * THEN we can be persistent, which requires more headers be output. * Note that the condition evaluation order is extremely important. (r->
chunked =
1))) &&
/* THIS CODE IS CORRECT, see comment above. */ /* If they sent a Keep-Alive token, send one back */ /* Otherwise, we need to indicate that we will be closing this * connection immediately after the current response. * We only really need to send "close" to HTTP/1.1 clients, but we * always send it anyway, because a broken proxy may identify itself * as HTTP/1.0, but pass our request along with our HTTP/1.1 tag * to a HTTP/1.1 client. Better safe than sorry. * Return the latest rational time from a request/mtime (modification time) * pair. We return the mtime unless it's in the future, in which case we * return the current time. We use the request time as a reference in order * to limit the number of calls to time(). We don't check for futurosity * unless the mtime is at least as new as the reference. /* For all static responses, it's almost certain that the file was * last modified before the beginning of the request. So there's * no reason to call time(NULL) again. But if the response has been * created on demand, then it might be newer than the time the request * started. In this event we really have to call time(NULL) again * so that we can give the clients the most accurate Last-Modified. If we * were given a time in the future, we return the current time - the * Last-Modified can't be in the future. /* Check for conditional requests --- note that we only want to do * this if we are successful so far and we are not processing a * subrequest or an ErrorDocument. * The order of the checks is important, since ETag checks are supposed * to be more accurate than checks relative to the modification time. * However, not all documents are guaranteed to *have* ETags, and some * might have Last-Modified values w/o ETags, so this gets a little /* XXX: we should define a "time unset" constant */ /* If an If-Match request-header field was given * AND the field value is not "*" (meaning match anything) * AND if our strong ETag does not match any entity tag in that field, * respond with a status of 412 (Precondition Failed). /* Else if a valid If-Unmodified-Since request-header field was given * AND the requested resource has been modified since the time * specified in this field, then the server MUST * respond with a status of 412 (Precondition Failed). /* If an If-None-Match request-header field was given * AND the field value is "*" (meaning match anything) * OR our ETag matches any of the entity tags in that field, fail. * If the request method was GET or HEAD, failure means the server * SHOULD respond with a 304 (Not Modified) response. * For all other request methods, failure means the server MUST * respond with a status of 412 (Precondition Failed). * GET or HEAD allow weak etag comparison, all other methods require * strong comparison. We can only use weak if it's not a range request. /* Else if a valid If-Modified-Since request-header field was given * AND it is a GET or HEAD request * AND the requested resource has not been modified since the time * specified in this field, then the server MUST * respond with a status of 304 (Not Modified). * A date later than the server's current request time is invalid. * Construct an entity tag (ETag) from resource information. If it's a real * file, build in some of the file characteristics. If the modification time * is newer than (request-time minus 1 second), mark the ETag as weak - it * could be modified again in as short an interval. We rationalize the * modification time we're given to keep it from being in the future. * Make an ETag header out of various pieces of information. We use * the last-modified date and, if we have a real file, the * length and inode number - note that this doesn't have to match * the content-length (i.e. includes), it just has to be unique * If the request was made within a second of the last-modified date, * we send a weak tag instead of a strong one, since it could * be modified again later in the second, and the validation "%s\"%lx-%lx-%lx\"",
weak,
(
unsigned long) r->
mtime);
(
unsigned long) r->
mtime);
/* If we have a variant list validator (vlv) due to the * response being negotiated, then we create a structured * entity tag which merges the variant etag with the variant * list validator (vlv). This merging makes revalidation * somewhat safer, ensures that caches which can deal with * Vary will (eventually) be updated if the set of variants is * changed, and is also a protocol requirement for transparent /* if the variant list validator is weak, we make the whole * structured etag weak. If we would not, then clients could * have problems merging range responses if we have different * variants with the same non-globally-unique strong etag. /* merge variant_etag and vlv into a structured etag */ * This function sets the Last-Modified output header field to the value * of the mtime field in the request structure - rationalized to keep it from /* Get the method number associated with the given string, assumed to * contain an HTTP method. Returns M_INVALID if not recognized. * This is the first step toward placing method names in a configurable * list. Hopefully it (and other routines) can eventually be moved to return M_GET;
/* see header_only in request_rec */ * Turn a known method number into a name. Doesn't work for * extension methods, obviously. * This is ugly, but the previous incantation made Windows C * varf. I'm not even sure it was ANSI C. However, ugly as it * is, this works, and we only have to do it once. * Since we're using symbolic names, make sure we only do * this once by forcing a value into the first slot IFF it's /* Get a line of protocol input, including any continuation lines * caused by MIME folding (or broken clients) if fold != 0, and place it * in the buffer s, of size n bytes, without the ending newline. * Returns -1 on error, or the length of s. * Note: Because bgets uses 1 char for newline and 1 char for NUL, * the most we can get is (n - 2) actual characters if it * was ended by a newline, or (n - 1) characters if the line * length exceeded (n - 1). So, if the result == (n - 1), * then the actual input line exceeded the buffer length, * and it would be a good idea for the caller to puke 400 or 414. /* When getline() is called, the HTTP protocol is in a state * where we MUST be reading "plain text" protocol stuff, * (Request line, MIME headers, Chunk sizes) regardless of * the MIME type and conversion setting of the document itself. * Save the current setting of the translation handle for * uploads, then temporarily set it to the one used for headers * (and restore it before returning). /* retval == -1 if error, 0 if EOF */ /* retval is the number of characters read, not including NUL */ n -=
retval;
/* Keep track of how much of s is full */ if (*
pos ==
'\n') {
/* Did we get a full line of input? */ * Trim any extra trailing spaces or tabs except for the first * space or tab at the beginning of a blank string. This makes * it much easier to check field values for exact matches, and * saves memory as well. Terminate string at end of line. while (
pos > (s +
1) && (*(
pos -
1) ==
' ' || *(
pos -
1) ==
'\t')) {
--
pos;
/* trim extra trailing spaces or tabs */ --
total;
/* but not one at the beginning of line */ break;
/* if not, input line exceeded buffer size */ /* Continue appending if line folding is desired and * the last line was not empty and we have room in the buffer and * the next line begins with a continuation character. /* restore translation handle */ /* parse_uri: break apart the uri * - sets r->args to rest after '?' (or NULL if no '?') * - sets r->uri to request uri (without r->args part) * - sets r->hostname (if not set already) from request (scheme://host:port) /* Simple syntax Errors in URLs are trapped by parse_uri_components(). */ /* if it has a scheme we may need to do absoluteURI vhost stuff */ /* Handle path translations for OS/2 and plug security hole. * returning a directory for the root drive. #
endif /* OS2 || WIN32 */ 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. /* 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); /* Provide quick information about the request method as soon as known */ /* 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. /* We'll use apr_overlap_tables later to merge these into r->headers_in. */ * Read header lines until we get the empty separator line, a read error, * the connection closes (EOF), reach the server limit, or we timeout. "The number of request header fields exceeds " "this server's limit.<P>\n");
/* 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 field size. "Size of a request header field exceeds server limit.<P>\n" "Request header field is missing colon separator.<P>\n" ++
value;
/* Skip to start of value */ "request failed: URI too long");
"request failed: error reading the headers");
* Client asked for headers only with HTTP/0.9, which doesn't send * headers! Have to dink things just to make sure the error message "client sent invalid HTTP/0.9 request: HEAD %s",
/* update what we think the virtual host is based on the headers we've * now read. may update status. /* we may have switched to another server */ * Client sent us an HTTP/1.1 or later request without telling us the * hostname, either with a full URL or a Host: header. We therefore * need to (as per the 1.1 spec) send an error. As a special case, * HTTP/1.1 mentions twice (S9, S14.23) that a request MUST contain * a Host: header, and the server MUST respond with 400 if it doesn't. "client sent HTTP/1.1 request without hostname " "(see RFC2068 section 9, and 14.23): %s", r->
uri);
* The Expect header field was added to HTTP/1.1 after RFC 2068 * as a means to signal when a 100 response is desired and, * unfortunately, to signal a poor man's mandatory extension that * the server must understand or return 417 Expectation Failed. "client sent an unrecognized expectation value of " * A couple of other functions which initialize some of the fields of * a request structure, as appropriate for adjuncts of one kind or another * to a request in progress. Best here, rather than elsewhere, since * *someone* has to set the protocol-specific fields... /* tell the filter chain there is no more content coming */ /* ### crap. we need to tell the subrequest's filters that no more ### is coming. there is definitely more for the parent requests. ### create a SUB_EOS bucket? /* end_output_stream(sub); */ * Support for the Basic authentication protocol, and a bit for Digest. r->
proxyreq ?
"Proxy-Authenticate" :
"WWW-Authenticate",
r->
proxyreq ?
"Proxy-Authenticate" :
"WWW-Authenticate",
0, r,
"need AuthName: %s", r->
uri);
/* Client tried to authenticate using wrong auth scheme */ "client used wrong authentication scheme: %s", r->
uri);
/* Note that this allocation has to be made from r->connection->pool * because it has the lifetime of the connection. The other allocations * are temporary and can be tossed away any time. /* New Apache routine to map status codes into array indicies * e.g. 100 -> 0, 101 -> 1, 200 -> 2 ... * The number of status lines must equal the value of RESPONSE_CODES (httpd.h) * and must be listed in order. /* The second const triggers an assembler bug on UTS 2.1. * Another workaround is to move some code out of this file into another, * but this is easier. Dave Dykstra, 3/31/99 "101 Switching Protocols",
"203 Non-Authoritative Information",
"307 Temporary Redirect",
"401 Authorization Required",
"405 Method Not Allowed",
"407 Proxy Authentication Required",
"412 Precondition Failed",
"413 Request Entity Too Large",
"414 Request-URI Too Large",
"415 Unsupported Media Type",
"416 Requested Range Not Satisfiable",
"417 Expectation Failed",
"422 Unprocessable Entity",
"500 Internal Server Error",
"501 Method Not Implemented",
"503 Service Temporarily Unavailable",
"505 HTTP Version Not Supported",
"506 Variant Also Negotiates",
"507 Insufficient Storage",
/* The index is found by its offset from the x00 code of each level. * Although this is fast, it will need to be replaced if some nutcase * decides to define a high-numbered code before the lower numbers. * If that sad event occurs, replace the code below with a linear search * from status_lines[shortcut[i]] to status_lines[shortcut[i+1]-1]; if (
status <
100)
/* Below 100 is illegal for HTTP status */ for (i = 0; i <
5; i++) {
return LEVEL_500;
/* status unknown (falls in gap) */ return LEVEL_500;
/* 600 or above is also illegal */ /* Send a single HTTP header field to the client. Note that this function * is used in calls to table_do(), so their interfaces are co-dependent. * In other words, don't change this one without checking table_do in alloc.c. * It returns true unless there was a write error of some kind. /* mod_proxy is only HTTP/1.0, so avoid sending HTTP/1.1 error response; * kluge around broken browsers when indicated by force-response-1.0 /* Output the HTTP/1.x Status-Line and the Date and Server fields */ /* Navigator versions 2.x, 3.x and 4.0 betas up to and including 4.0b2 * have a header parsing bug. If the terminating \r\n occur starting * at offset 256, 257 or 258 of output then it will not properly parse * the headers. Curiously it doesn't exhibit this problem at 512, 513. * We are guessing that this is because their initial read of a new request * uses a 256 byte buffer, and subsequent reads use a larger buffer. * So the problem might exist at different offsets as well. * This should also work on keepalive connections assuming they use the * same small buffer for the first read of each new request. * At any rate, we check the bytes written so far and, if we are about to * tickle the bug, we instead insert a bogus padding header. Since the bug * manifests as a broken image in Navigator, users blame the server. :( * It is more expensive to check the User-Agent than it is to just add the * bytes, so we haven't used the BrowserMatch feature here. if (
bs >=
255 &&
bs <=
257)
/* Build the Allow field-value from the request handler method mask. * Note that we always allow TRACE, since it is handled below. * Append all of the elements of r->allowed_xmethods * Space past the leading ", ". Wastes two bytes, but that's better * than futzing around to find the actual length. /* Get the original request */ /* Now we recreate the request, and echo it back */ const long int zero = 0L;
* look for the Request-Range header (e.g. Netscape 2 and 3) as an indication * that the browser supports an older protocol. We also check User-Agent * for Microsoft Internet Explorer 3, which needs this as well. /* This routine is called by apr_table_do and merges all instances of * the passed field values into a single array that will be further * processed by some later routine. Originally intended to help split * and recombine multiple Vary fields, though it is generic to any field /* Find a non-empty fieldname */ /* Now add it to values if it isn't already represented. * Could be replaced by a ap_array_strcasecmp() if we had one. * Since some clients choke violently on multiple Vary fields, or * Vary fields with duplicate tokens, combine any multiples and remove /* Extract all Vary fields from the headers_out, separate each into * its comma-separated fieldname values, and then add them to varies * if not already present in the array. /* If we found any, replace old Vary fields with unique-ified value */ const long int zero = 0L;
/* By default, we convert all content. ap_checkconv() can decide * that conversion shouldn't be performed. Also, if the content type * contains the "magic" prefix for serving raw ascii * (text/x-ascii-{plain,html,...}), the type is corrected to the real * text/{plain,html,...} type which goes into the headers. * This may not seem like the best place to put this call, but doing * it here avoids having to call it in every handler (which is * particularly hard to do with handlers in modules which aren't * part of the Apache httpd distribution). * Now that we are ready to send a response, we need to combine the two * header field tables into a single table. If we don't do this, our * later attempts to set or unset a given fieldname might be bypassed. * Remove the 'Vary' header field if the client can't handle it. * Since this will have nasty effects on HTTP/1.1 caches, force * the response into HTTP/1.0 mode. * Control cachability for non-cachable responses if not already set by * some other part of the server configuration. r->
sent_bodyct =
1;
/* Whatever follows is real body stuff... */ /* Set buffer flags for the body */ /* finalize_request_protocol is called at completion of sending the * response. Its sole purpose is to send the terminating protocol * information for any wrappers around the response message body * (i.e., transfer encodings). It should have been named finalize_response. /* tell the filter chain there is no more content coming */ /* Here we deal with getting the request message body from the client. * Whether or not the request contains a body is signaled by the presence * of a non-zero Content-Length or by a Transfer-Encoding: chunked. * Note that this is more complicated than it was in Apache 1.1 and prior * versions, because chunked support means that the module does less. * The proper procedure is this: * 1. Call setup_client_block() near the beginning of the request * handler. This will set up all the necessary properties, and will * return either OK, or an error code. If the latter, the module should * return that error code. The second parameter selects the policy to * apply if the request message indicates a body, and how a chunked * transfer-coding should be interpreted. Choose one of * REQUEST_NO_BODY Send 413 error if message has any body * REQUEST_CHUNKED_ERROR Send 411 error if body without Content-Length * REQUEST_CHUNKED_DECHUNK If chunked, remove the chunks for me. * REQUEST_CHUNKED_PASS Pass the chunks to me without removal. * In order to use the last two options, the caller MUST provide a buffer * large enough to hold a chunk-size line, including any extensions. * 2. When you are ready to read a body (if any), call should_client_block(). * This will tell the module whether or not to read input. If it is 0, * the module should assume that there is no message body to read. * This step also sends a 100 Continue response to HTTP/1.1 clients, * so should not be called until the module is *definitely* ready to * read content. (otherwise, the point of the 100 response is defeated). * Never call this function more than once. * 3. Finally, call get_client_block in a loop. Pass it a buffer and its size. * It will put data into the buffer (not necessarily a full buffer), and * return the length of the input block. When it is done reading, it will * return 0 if EOF, or -1 if there was an error. * If an error occurs on input, we force an end to keepalive. "Unknown Transfer-Encoding %s",
tenc);
"chunked Transfer-Encoding forbidden: %s", r->
uri);
"Invalid Content-Length %s",
lenp);
"%s with body is not allowed for %s", r->
method, r->
uri);
"Request content-length of %s is larger than the configured " /* @@@ Temporary kludge for guessing the conversion @@@ * from looking at the MIME header. * If no Content-Type header is found, text conversion is assumed. /* By default, we translate content on input. Turn off translation #
endif /*CHARSET_EBCDIC*/ /* First check if we have already read the request body */ /* sending 100 Continue interim response */ if (*b >=
'0' && *b <=
'9')
else if (*b >=
'A' && *b <=
'F')
else if (*b >=
'a' && *b <=
'f')
/* get_client_block is called in a loop to get the request message body. * This is quite simple if the client includes a content-length * (the normal case), but gets messy if the body is chunked. Note that * r->remaining is used to maintain state across calls and that * r->read_length is the total number of bytes given to the caller * across all invocations. It is messy because we have to be careful not * to read past the data provided by the client, since these reads block. * Returns 0 on End-of-body, -1 on error or premature chunk end. * Reading the chunked encoding requires a buffer size large enough to * hold a chunk-size line, including any extensions. For now, we'll leave * that to the caller, at least until we can come up with a better solution. * Handle chunked reading Note: we are careful to shorten the input * bufsiz so that there will always be enough space for us to add a CRLF return -
1;
/* Cannot read chunked with a small buffer */ /* Check to see if we have already read too much request data. * For efficiency reasons, we only check this at the top of each * caller read pass, since the limit exists just to stop infinite * length requests and nobody cares if it goes over by one buffer. "Chunked request body is larger than the configured limit of %lu",
if (r->
remaining == 0) {
/* Start of new chunk */ if (
len_to_read == 0) {
/* Last chunk indicated, get footers */ r->
remaining = -
1;
/* Indicate footers in-progress */ /* REQUEST_CHUNKED_DECHUNK -- do not include the length of the * header in the return value /* When REQUEST_CHUNKED_PASS, we are */ if (r->
remaining == -
1) {
/* reading footers until empty line */ if (
len_read == 0) {
/* Indicates an empty line */ /* When REQUEST_CHUNKED_PASS, we */ if (r->
remaining == -
2) {
/* finished footers when last called */ r->
remaining = 0;
/* so now we must signal EOF */ /* Otherwise, we are in the midst of reading a chunk of data */ if (r->
remaining == 0) {
/* End of chunk, get trailing CRLF */ /* Chunk end is Protocol stuff! Set conversion = 1 to read CR LF: */ /* restore previous input translation handle */ /* In HTTP/1.1, any method can have a body. However, most GET handlers * wouldn't know what to do with a request body if they received one. * This helper routine tests for and reads any message body in the request, * simply discarding whatever it receives. We need to do this because * failing to read the request body would cause it to be interpreted * as the next request on a persistent connection. * Since we return an error status if the request is malformed, this * routine should be called at the beginning of a no-body handler, e.g., * if ((retval = ap_discard_request_body(r)) != OK) /* In order to avoid sending 100 Continue when we already know the * final response status, and yet not kill the connection if there is * no request body to be read, we need to duplicate the test from * ap_should_client_block() here negated rather than call it directly. * We want to send any data held in the client buffer on the * call to apr_sendfile. So hijack it then set outcnt to 0 * to prevent the data from being sent to the client again * when the buffer is flushed to the client at the end of the /* initialize the apr_hdtr_t struct */ /* Prepare the socket to be reused */ /* XXX fix me - byteranges? */ fd,
/* The file to send */ &
hdtr,
/* Header and trailer iovecs */ &
offset,
/* Offset in file to begin sending from */ * Send the body of a response to the client. /* Chunked encoding must be handled in the BUFF */ /* Don't consider APR_ENOTIMPL a failure */ /* Either sendfile is not defined or it failed with APR_ENOTIMPL */ /* Seek the file to the offset */ /* apr_close(fd); close the file or let the caller handle it? */ /* Is this still the right check? maybe check for n==0 or rv == APR_EOF? */ * Send the body of a response to the client. /* This function tries to as much as possible through non-blocking * reads so that it can do writes while waiting for the CGI to * produce more data. This way, the CGI's output gets to the client /* Regardless of read errors, EOF, etc, bytes may have been read */ /* Assume a sucessful read of 0 bytes is an EOF * Note: I don't think this is ultimately the right thing. * Read functions should explicitly return EOF. /* next read will block, so flush the client now */ /* The code writes MMAP_SEGMENT_SIZE bytes at a time. This is due to Apache's * timeout model, which is a timeout per-write rather than a time for the * entire transaction to complete. Essentially this should be small enough * so that in one Timeout period, your slowest clients should be reasonably * able to receive this many bytes. * To take advantage of zero-copy TCP under Solaris 2.6 this should be a * multiple of 16k. (And you need a SunATM2.0 network card.) /* send data from an in-memory buffer */ /* WE probably need to do something to make sure we are respecting the * offset and length. I think I know how to do this, but I will wait * until after the commit to actually write the code. return mm->
size;
/* XXX - change API to report apr_status_t? */ #
endif /* USE_MMAP_FILES *//* TODO: Make ap pa_bucket_vprintf that printfs directly into a /* ### this is probably incorrect, but we have no mechanism for telling ### the filter chain to flush any content they may be holding. ### add a FLUSH bucket type? /* We should have named this send_canned_response, since it is used for any * response that can be generated by the server from the request record. * This includes all 204 (no content), 3xx (redirect), 4xx (client error), * and 5xx (server error) messages that have not been redirected to another * handler via the ErrorDocument feature. * It's possible that the Location field might be in r->err_headers_out * instead of r->headers_out; use the latter if possible, else the /* We need to special-case the handling of 204 and 304 responses, * since they have specific HTTP requirements and do not include a * message body. Note that being assbackwards here is not an option. /* For all HTTP/1.x responses for which we generate the message, * we need to avoid inheriting the "normal status" header fields * that may have been set by the request handler before the * error or redirect, except for Location on external redirects. location =
"";
/* avoids coredump when printing, below */ /* Ensure that the proper translation handle (if any) is used when * sending the response document to the client. Note that on an * ASCII machine, ap_hdrs_to_ascii is NULL, so this will turn off * any translation selected by a module for content. * We have a custom response output. This should only be * a text-string to write back. But if the ErrorDocument * was a local redirect and the requested resource failed * for any reason, the custom_response will still hold the * redirect URL. We don't really want to output this URL * as a text message, so first check the custom response * string to ensure that it is a text-string (using the * same test used in ap_die(), i.e. does it start with a "). * If it doesn't, we've got a recursive error, so find * the original error and output that as well. * Redirect failed, so get back the original error /* Accept a status_line set by a module, but only if it begins * with the 3 digit status code /* folks decided they didn't want the error code in the H1 text */ "<HTML><HEAD>\n<TITLE>",
title,
"</TITLE>\n</HEAD><BODY>\n<H1>",
h1,
"</H1>\n",
ap_rvputs(r,
"The document has moved <A HREF=\"",
ap_rvputs(r,
"The answer to your request is located <A HREF=\"",
ap_rvputs(r,
"This resource is only accessible " "<BR>\nYou will need to ",
"configure your client to use that proxy.<P>\n",
NULL);
ap_rputs(
"This server could not verify that you\n" "are authorized to access the document\n" "requested. Either you supplied the wrong\n" "credentials (e.g., bad password), or your\n" "browser doesn't understand how to supply\n" "the credentials required.<P>\n", r);
ap_rputs(
"Your browser sent a request that " "this server could not understand.<P>\n", r);
ap_rvputs(r,
"You don't have permission to access ",
"\non this server.<P>\n",
NULL);
" was not found on this server.<P>\n",
NULL);
"An appropriate representation of the " " could not be found on this server.<P>\n",
NULL);
" requires a valid Content-length.<P>\n",
NULL);
ap_rvputs(r,
"The precondition on the request for the URL ",
" evaluated to false.<P>\n",
NULL);
" not supported.<P>\n",
NULL);
"response from an upstream server.<P>" CRLF, r);
ap_rvputs(r,
"A variant for the requested resource\n<PRE>\n",
"\n</PRE>\nis itself a negotiable resource. " "This indicates a configuration error.<P>\n",
NULL);
ap_rputs(
"I'm tired of waiting for your request.\n", r);
"<BR>\nis no longer available on this server ",
"and there is no forwarding address.\n",
"Please remove all references to this resource.\n",
"does not allow request data with ", r->
method,
" requests, or the amount of data provided in\n",
"the request exceeds the capacity limit.\n",
NULL);
ap_rputs(
"The requested URL's length exceeds the capacity\n" "limit for this server.<P>\n", r);
ap_rputs(
"The supplied request data is not in a format\n" "acceptable for processing by this resource.\n", r);
ap_rputs(
"None of the range-specifier values in the Range\n" "request-header field overlap the current extent\n" "of the selected resource.\n", r);
ap_rvputs(r,
"The expectation given in the Expect request-header" "\nfield could not be met by this server.<P>\n" "The client sent<PRE>\n Expect: ",
"but we only allow the 100-continue expectation.\n",
ap_rputs(
"The server understands the media type of the\n" "request entity, but was unable to process the\n" "contained instructions.\n", r);
ap_rputs(
"The requested resource is currently locked.\n" "The lock must be released or proper identification\n" "given before the method can be applied.\n", r);
ap_rputs(
"The method could not be performed on the resource\n" "because the requested action depended on another\n" "action and that other action failed.\n", r);
ap_rputs(
"The method could not be performed on the resource\n" "because the server is unable to store the\n" "representation needed to successfully complete the\n" "request. There is insufficient free space left in\n" "your storage allocation.\n", r);
ap_rputs(
"The server is temporarily unable to service your\n" "request due to maintenance downtime or capacity\n" "problems. Please try again later.\n", r);
ap_rputs(
"The proxy server did not receive a timely response\n" "from the upstream server.\n", r);
ap_rputs(
"A mandatory extension policy in the request is not\n" "accepted by the server for this resource.\n", r);
default:
/* HTTP_INTERNAL_SERVER_ERROR */ * This comparison to expose error-notes could be modified to * use a configuration directive and export based on that * directive. For now "*" is used to designate an error-notes * that is totally safe for any user to see (ie lacks paths, * database passwords, etc.) ap_rvputs(r,
"The server encountered an internal error or\n" "misconfiguration and was unable to complete\n" "Please contact the server administrator,\n ",
" and inform them of the time the error occurred,\n" "and anything you might have done that may have\n" "More information about this error may be available\n" "in the server error log.<P>\n",
NULL);
* It would be nice to give the user the information they need to * fix the problem directly since many users don't have access to * the error_log (think University sites) even though they can easily * get this error by misconfiguring an htaccess file. However, the * error notes tend to include the real file pathname in this case, * which some people consider to be a breach of privacy. Until we * can figure out a way to remove the pathname, leave this commented. * if ((error_notes = apr_table_get(r->notes, "error-notes")) != NULL) { * ap_rvputs(r, error_notes, "<P>\n", NULL); "\nerror was encountered while trying to use an " "ErrorDocument to handle the request.\n",
NULL);