Apache HTTPD
protocol.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * protocol.c --- routines which directly communicate with the client.
19 *
20 * Code originally by Rob McCool; much redone by Robert S. Thau
21 * and the Apache Software Foundation.
22 */
23
24#include "apr.h"
25#include "apr_strings.h"
26#include "apr_buckets.h"
27#include "apr_lib.h"
28#include "apr_signal.h"
29#include "apr_strmatch.h"
30
31#define APR_WANT_STDIO /* for sscanf */
32#define APR_WANT_STRFUNC
33#define APR_WANT_MEMFUNC
34#include "apr_want.h"
35
36#include "util_filter.h"
37#include "ap_config.h"
38#include "httpd.h"
39#include "http_config.h"
40#include "http_core.h"
41#include "http_protocol.h"
42#include "http_main.h"
43#include "http_request.h"
44#include "http_vhost.h"
45#include "http_log.h" /* For errors detected in basic auth common
46 * support code... */
47#include "mod_core.h"
48#include "util_charset.h"
49#include "util_ebcdic.h"
50#include "scoreboard.h"
51
52#if APR_HAVE_STDARG_H
53#include <stdarg.h>
54#endif
55#if APR_HAVE_UNISTD_H
56#include <unistd.h>
57#endif
58
59/* we know core's module_index is 0 */
60#undef APLOG_MODULE_INDEX
61#define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
62
68 APR_HOOK_LINK(default_port)
74
76
77
78/* Patterns to match in ap_make_content_type() */
80 "text/plain",
81 "text/html",
82 NULL
83};
86
88{
89 int i;
90 for (i = 0; needcset[i]; i++) {
91 continue;
92 }
94 apr_palloc(pool, (i + 1) * sizeof(apr_strmatch_pattern *));
95 for (i = 0; needcset[i]; i++) {
97 }
100}
101
102/*
103 * Builds the content-type that should be sent to the client from the
104 * content-type specified. The following rules are followed:
105 * - if type is NULL or "", return NULL (do not set content-type).
106 * - if charset adding is disabled, stop processing and return type.
107 * - then, if there are no parameters on type, add the default charset
108 * - return type
109 */
111{
113 core_dir_config *conf =
116 apr_size_t type_len;
117
118 if (!type || *type == '\0') {
119 return NULL;
120 }
121
123 return type;
124 }
125
127 if (request_conf->suppress_charset) {
128 return type;
129 }
130
131 type_len = strlen(type);
132
133 if (apr_strmatch(charset_pattern, type, type_len) != NULL) {
134 /* already has parameter, do nothing */
135 /* XXX we don't check the validity */
136 ;
137 }
138 else {
139 /* see if it makes sense to add the charset. At present,
140 * we only add it if the Content-type is one of needcset[]
141 */
142 for (pcset = needcset_patterns; *pcset ; pcset++) {
143 if (apr_strmatch(*pcset, type, type_len) != NULL) {
144 struct iovec concat[3];
145 concat[0].iov_base = (void *)type;
146 concat[0].iov_len = type_len;
147 concat[1].iov_base = (void *)"; charset=";
148 concat[1].iov_len = sizeof("; charset=") - 1;
149 concat[2].iov_base = (void *)(conf->add_default_charset_name);
150 concat[2].iov_len = strlen(conf->add_default_charset_name);
152 break;
153 }
154 }
155 }
156
157 return type;
158}
159
161{
162 r->clength = clength;
163 apr_table_setn(r->headers_out, "Content-Length",
164 apr_off_t_toa(r->pool, clength));
165}
166
167/*
168 * Return the latest rational time from a request/mtime (modification time)
169 * pair. We return the mtime unless it's in the future, in which case we
170 * return the current time. We use the request time as a reference in order
171 * to limit the number of calls to time(). We don't check for futurosity
172 * unless the mtime is at least as new as the reference.
173 */
175{
177
178 /* For all static responses, it's almost certain that the file was
179 * last modified before the beginning of the request. So there's
180 * no reason to call time(NULL) again. But if the response has been
181 * created on demand, then it might be newer than the time the request
182 * started. In this event we really have to call time(NULL) again
183 * so that we can give the clients the most accurate Last-Modified. If we
184 * were given a time in the future, we return the current time - the
185 * Last-Modified can't be in the future.
186 */
188 return (mtime > now) ? now : mtime;
189}
190
191/* Get a line of protocol input, including any continuation lines
192 * caused by MIME folding (or broken clients) if fold != 0, and place it
193 * in the buffer s, of size n bytes, without the ending newline.
194 *
195 * Pulls from r->proto_input_filters instead of r->input_filters for
196 * stricter protocol adherence and better input filter behavior during
197 * chunked trailer processing (for http).
198 *
199 * If s is NULL, ap_rgetline_core will allocate necessary memory from r->pool.
200 *
201 * Returns APR_SUCCESS if there are no problems and sets *read to be
202 * the full length of s.
203 *
204 * APR_ENOSPC is returned if there is not enough buffer space.
205 * Other errors may be returned on other errors.
206 *
207 * The [CR]LF are *not* returned in the buffer. Therefore, a *read of 0
208 * indicates that an empty line was read.
209 *
210 * Notes: Because the buffer uses 1 char for NUL, the most we can return is
211 * (n - 1) actual characters.
212 *
213 * If no LF is detected on the last line due to a dropped connection
214 * or a full buffer, that's considered an error.
215 */
217 apr_size_t *read, request_rec *r,
218 int flags, apr_bucket_brigade *bb)
219{
220 apr_status_t rv;
221 apr_bucket *e;
223 char *pos, *last_char = *s;
224 int do_alloc = (*s == NULL), saw_eos = 0;
225 int fold = flags & AP_GETLINE_FOLD;
226 int crlf = flags & AP_GETLINE_CRLF;
228 int saw_eol = 0, saw_nospc = 0;
229
230 if (!n) {
231 /* Needs room for NUL byte at least */
232 *read = 0;
233 return APR_BADARG;
234 }
235
236 /*
237 * Initialize last_char as otherwise a random value will be compared
238 * against APR_ASCII_LF at the end of the loop if bb only contains
239 * zero-length buckets.
240 */
241 if (last_char)
242 *last_char = '\0';
243
244 do {
247 APR_BLOCK_READ, 0);
248 if (rv != APR_SUCCESS) {
249 goto cleanup;
250 }
251
252 /* Something horribly wrong happened. Someone didn't block!
253 * (this also happens at the end of each keepalive connection)
254 */
255 if (APR_BRIGADE_EMPTY(bb)) {
256 rv = APR_EGENERAL;
257 goto cleanup;
258 }
259
260 for (e = APR_BRIGADE_FIRST(bb);
261 e != APR_BRIGADE_SENTINEL(bb);
263 {
264 const char *str;
266
267 /* If we see an EOS, don't bother doing anything more. */
268 if (APR_BUCKET_IS_EOS(e)) {
269 saw_eos = 1;
270 break;
271 }
272
274 if (rv != APR_SUCCESS) {
275 goto cleanup;
276 }
277
278 if (len == 0) {
279 /* no use attempting a zero-byte alloc (hurts when
280 * using --with-efence --enable-pool-debug) or
281 * doing any of the other logic either
282 */
283 continue;
284 }
285
286 /* Would this overrun our buffer? If so, we'll die. */
287 if (n < bytes_handled + len) {
288 /* Before we die, let's fill the buffer up to its limit (i.e.
289 * fall through with the remaining length, if any), setting
290 * saw_eol on LF to stop the outer loop appropriately; we may
291 * come back here once the buffer is filled (no LF seen), and
292 * either be done at that time or continue to wait for LF here
293 * if nospc_eol is set.
294 *
295 * But there is also a corner cases which we want to address,
296 * namely if the buffer is overrun by the final LF only (i.e.
297 * the CR fits in); this is not really an overrun since we'll
298 * strip the CR finally (and use it for NUL byte), but anyway
299 * we have to handle the case so that it's not returned to the
300 * caller as part of the truncated line (it's not!). This is
301 * easier to consider that LF is out of counting and thus fall
302 * through with no error (saw_eol is set to 2 so that we later
303 * ignore LF handling already done here), while folding and
304 * nospc_eol logics continue to work (or fail) appropriately.
305 */
306 saw_eol = (str[len - 1] == APR_ASCII_LF);
307 if (/* First time around */
309 /* Single LF completing the buffered CR, */
310 && ((len == 1 && ((*s)[bytes_handled - 1] == APR_ASCII_CR))
311 /* or trailing CRLF overuns by LF only */
312 || (len > 1 && str[len - 2] == APR_ASCII_CR
313 && n - bytes_handled + 1 == len))) {
314 /* In both cases *last_char is (to be) the CR stripped by
315 * later 'bytes_handled = last_char - *s'.
316 */
317 saw_eol = 2;
318 }
319 else {
320 /* In any other case we'd lose data. */
321 rv = APR_ENOSPC;
322 saw_nospc = 1;
323 }
324 len = n - bytes_handled;
325 if (!len) {
326 if (saw_eol) {
327 break;
328 }
329 if (nospc_eol) {
330 continue;
331 }
332 goto cleanup;
333 }
334 }
335
336 /* Do we have to handle the allocation ourselves? */
337 if (do_alloc) {
338 /* We'll assume the common case where one bucket is enough. */
339 if (!*s) {
341 *s = apr_palloc(r->pool, current_alloc + 1);
342 }
343 else if (bytes_handled + len > current_alloc) {
344 /* Increase the buffer size */
346 char *new_buffer;
347
348 if (bytes_handled + len > new_size) {
349 new_size = (bytes_handled + len) * 2;
350 }
351
353
354 /* Copy what we already had. */
357 *s = new_buffer;
358 }
359 }
360
361 /* Just copy the rest of the data to the end of the old buffer. */
362 pos = *s + bytes_handled;
363 memcpy(pos, str, len);
364 last_char = pos + len - 1;
365
366 /* We've now processed that new data - update accordingly. */
368 }
369
370 /* If we got a full line of input, stop reading */
371 if (last_char && (*last_char == APR_ASCII_LF)) {
372 saw_eol = 1;
373 }
374 } while (!saw_eol);
375
376 if (rv != APR_SUCCESS) {
377 /* End of line after APR_ENOSPC above */
378 goto cleanup;
379 }
380
381 /* Now terminate the string at the end of the line;
382 * if the last-but-one character is a CR, terminate there.
383 * LF is handled above (not accounted) when saw_eol == 2,
384 * the last char is CR to terminate at still.
385 */
386 if (saw_eol < 2) {
387 if (last_char > *s && last_char[-1] == APR_ASCII_CR) {
388 last_char--;
389 }
390 else if (crlf) {
391 rv = APR_EINVAL;
392 goto cleanup;
393 }
394 }
396
397 /* If we're folding, we have more work to do.
398 *
399 * Note that if an EOS was seen, we know we can't have another line.
400 */
401 if (fold && bytes_handled && !saw_eos) {
402 for (;;) {
403 const char *str;
405 char c;
406
407 /* Clear the temp brigade for this filter read. */
409
410 /* We only care about the first byte. */
412 APR_BLOCK_READ, 1);
413 if (rv != APR_SUCCESS) {
414 goto cleanup;
415 }
416
417 if (APR_BRIGADE_EMPTY(bb)) {
418 break;
419 }
420
421 e = APR_BRIGADE_FIRST(bb);
422
423 /* If we see an EOS, don't bother doing anything more. */
424 if (APR_BUCKET_IS_EOS(e)) {
425 break;
426 }
427
429 if (rv != APR_SUCCESS) {
431 goto cleanup;
432 }
433
434 /* Found one, so call ourselves again to get the next line.
435 *
436 * FIXME: If the folding line is completely blank, should we
437 * stop folding? Does that require also looking at the next
438 * char?
439 */
440 /* When we call destroy, the buckets are deleted, so save that
441 * one character we need. This simplifies our execution paths
442 * at the cost of one character read.
443 */
444 c = *str;
445 if (c == APR_ASCII_BLANK || c == APR_ASCII_TAB) {
446 /* Do we have enough space? We may be full now. */
447 if (bytes_handled >= n) {
448 rv = APR_ENOSPC;
449 goto cleanup;
450 }
451 else {
453 char *tmp;
454
455 /* If we're doing the allocations for them, we have to
456 * give ourselves a NULL and copy it on return.
457 */
458 if (do_alloc) {
459 tmp = NULL;
460 }
461 else {
462 tmp = last_char;
463 }
464
466
467 rv = ap_rgetline_core(&tmp, next_size, &next_len, r,
468 flags & ~AP_GETLINE_FOLD, bb);
469 if (rv != APR_SUCCESS) {
470 goto cleanup;
471 }
472
473 if (do_alloc && next_len > 0) {
474 char *new_buffer;
476
477 /* we need to alloc an extra byte for a null */
479
480 /* Copy what we already had. */
482
483 /* copy the new line, including the trailing null */
485 *s = new_buffer;
486 }
487
490 }
491 }
492 else { /* next character is not tab or space */
493 break;
494 }
495 }
496 }
497
498cleanup:
499 if (bytes_handled >= n) {
500 bytes_handled = n - 1;
501 }
502
503 *read = bytes_handled;
504 if (*s) {
505 /* ensure the string is NUL terminated */
506 (*s)[*read] = '\0';
507
508 /* PR#43039: We shouldn't accept NULL bytes within the line */
509 bytes_handled = strlen(*s);
510 if (bytes_handled < *read) {
512 "NULL bytes in header", *s, *read, 0);
513 *read = bytes_handled;
514 if (rv == APR_SUCCESS) {
515 rv = APR_EINVAL;
516 }
517 }
518 }
519 return rv;
520}
521
522#if APR_CHARSET_EBCDIC
524 apr_size_t *read, request_rec *r,
525 int fold, apr_bucket_brigade *bb)
526{
527 /* on ASCII boxes, ap_rgetline is a macro which simply invokes
528 * ap_rgetline_core with the same parms
529 *
530 * on EBCDIC boxes, each complete http protocol input line needs to be
531 * translated into the code page used by the compiler. Since
532 * ap_rgetline_core uses recursion, we do the translation in a wrapper
533 * function to ensure that each input character gets translated only once.
534 */
535 apr_status_t rv;
536
537 rv = ap_rgetline_core(s, n, read, r, fold, bb);
538 if (rv == APR_SUCCESS || APR_STATUS_IS_ENOSPC(rv)) {
540 }
541 return rv;
542}
543#endif
544
545AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int flags)
546{
547 char *tmp_s = s;
548 apr_status_t rv;
550 apr_bucket_brigade *tmp_bb;
551
552 if (n < 1) {
553 /* Can't work since we always NUL terminate */
554 return -1;
555 }
556
558 rv = ap_rgetline(&tmp_s, n, &len, r, flags, tmp_bb);
559 apr_brigade_destroy(tmp_bb);
560
561 /* Map the out-of-space condition to the old API. */
562 if (rv == APR_ENOSPC) {
563 return n;
564 }
565
566 /* Anything else is just bad. */
567 if (rv != APR_SUCCESS) {
568 return -1;
569 }
570
571 return (int)len;
572}
573
574/* parse_uri: break apart the uri
575 * Side Effects:
576 * - sets r->args to rest after '?' (or NULL if no '?')
577 * - sets r->uri to request uri (without r->args part)
578 * - sets r->hostname (if not set already) from request (scheme://host:port)
579 */
581{
582 int status = HTTP_OK;
583
585
586 /* http://issues.apache.org/bugzilla/show_bug.cgi?id=31875
587 * http://issues.apache.org/bugzilla/show_bug.cgi?id=28450
588 *
589 * This is not in fact a URI, it's a path. That matters in the
590 * case of a leading double-slash. We need to resolve the issue
591 * by normalizing that out before treating it as a URI.
592 */
593 while ((uri[0] == '/') && (uri[1] == '/')) {
594 ++uri ;
595 }
596 if (r->method_number == M_CONNECT) {
598 }
599 else {
601 }
602
603 if (status == APR_SUCCESS) {
604 /* if it has a scheme we may need to do absoluteURI vhost stuff */
605 if (r->parsed_uri.scheme
608 }
609 else if (r->method_number == M_CONNECT) {
611 }
612
613 r->args = r->parsed_uri.query;
614 if (r->parsed_uri.path) {
615 r->uri = r->parsed_uri.path;
616 }
617 else if (r->method_number == M_OPTIONS) {
618 r->uri = apr_pstrdup(r->pool, "*");
619 }
620 else {
621 r->uri = apr_pstrdup(r->pool, "/");
622 }
623
624#if defined(OS2) || defined(WIN32)
625 /* Handle path translations for OS/2 and plug security hole.
626 * This will prevent "http://www.wherever.com/..\..\/" from
627 * returning a directory for the root drive.
628 */
629 {
630 char *x;
631
632 for (x = r->uri; (x = strchr(x, '\\')) != NULL; )
633 *x = '/';
634 }
635#endif /* OS2 || WIN32 */
636 }
637 else {
638 r->args = NULL;
639 r->hostname = NULL;
640 r->status = HTTP_BAD_REQUEST; /* set error status */
641 r->uri = apr_pstrdup(r->pool, uri);
642 }
643}
644
645/* get the length of the field name for logging, but no more than 80 bytes */
646#define LOG_NAME_MAX_LEN 80
647static int field_name_len(const char *field)
648{
649 const char *end = ap_strchr_c(field, ':');
650 if (end == NULL || end - field > LOG_NAME_MAX_LEN)
651 return LOG_NAME_MAX_LEN;
652 return end - field;
653}
654
656{
660 int strict = (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE);
661
662 /* Read past empty lines until we get a real request line,
663 * a read error, the connection closes (EOF), or we timeout.
664 *
665 * We skip empty lines because browsers have to tack a CRLF on to the end
666 * of POSTs to support old CERN webservers. But note that we may not
667 * have flushed any previous response completely to the client yet.
668 * We delay the flush as long as possible so that we can improve
669 * performance for clients that are pipelining requests. If a request
670 * is pipelined then we won't block during the (implicit) read() below.
671 * If the requests aren't pipelined, then the client is still waiting
672 * for the final buffer flush from us, and we will block in the implicit
673 * read(). B_SAFEREAD ensures that the BUFF layer flushes if it will
674 * have to block during a read.
675 */
676
677 do {
678 apr_status_t rv;
679
680 /* ensure ap_rgetline allocates memory each time thru the loop
681 * if there are empty lines
682 */
683 r->the_request = NULL;
685 &len, r, strict ? AP_GETLINE_CRLF : 0, bb);
686
687 if (rv != APR_SUCCESS) {
689
690 /* ap_rgetline returns APR_ENOSPC if it fills up the
691 * buffer before finding the end-of-line. This is only going to
692 * happen if it exceeds the configured limit for a request-line.
693 */
694 if (APR_STATUS_IS_ENOSPC(rv)) {
696 }
697 else if (APR_STATUS_IS_TIMEUP(rv)) {
699 }
700 else if (APR_STATUS_IS_EINVAL(rv)) {
702 }
703 r->proto_num = HTTP_VERSION(1,0);
704 r->protocol = apr_pstrdup(r->pool, "HTTP/1.0");
705 return 0;
706 }
707 } while ((len <= 0) && (--num_blank_lines >= 0));
708
709 /* Set r->request_time before any logging, mod_unique_id needs it. */
711
712 if (APLOGrtrace5(r)) {
714 "Request received from client: %s",
716 }
717
718 return 1;
719}
720
722{
724 int strict = (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE);
725 enum {
730 apr_size_t len = 0;
731 char *uri, *ll;
732
733 r->method = r->the_request;
734
735 /* If there is whitespace before a method, skip it and mark in error */
736 if (apr_isspace(*r->method)) {
738 for ( ; apr_isspace(*r->method); ++r->method)
739 ;
740 }
741
742 /* Scan the method up to the next whitespace, ensure it contains only
743 * valid http-token characters, otherwise mark in error
744 */
745 if (strict) {
746 ll = (char*) ap_scan_http_token(r->method);
747 }
748 else {
749 ll = (char*) ap_scan_vchar_obstext(r->method);
750 }
751
752 if (((ll == r->method) || (*ll && !apr_isspace(*ll)))
753 && deferred_error == rrl_none) {
755 ll = strpbrk(ll, "\t\n\v\f\r ");
756 }
757
758 /* Verify method terminated with a single SP, or mark as specific error */
759 if (!ll) {
762 r->protocol = uri = "";
763 goto rrl_done;
764 }
765 else if (strict && ll[0] && apr_isspace(ll[1])
766 && deferred_error == rrl_none) {
768 }
769
770 /* Advance uri pointer over leading whitespace, NUL terminate the method
771 * If non-SP whitespace is encountered, mark as specific error
772 */
773 for (uri = ll; apr_isspace(*uri); ++uri)
774 if (*uri != ' ' && deferred_error == rrl_none)
776 *ll = '\0';
777
778 if (!*uri && deferred_error == rrl_none)
780
781 /* Scan the URI up to the next whitespace, ensure it contains no raw
782 * control characters, otherwise mark in error
783 */
784 ll = (char*) ap_scan_vchar_obstext(uri);
785 if (ll == uri || (*ll && !apr_isspace(*ll))) {
787 ll = strpbrk(ll, "\t\n\v\f\r ");
788 }
789
790 /* Verify URI terminated with a single SP, or mark as specific error */
791 if (!ll) {
792 r->protocol = "";
793 goto rrl_done;
794 }
795 else if (strict && ll[0] && apr_isspace(ll[1])
796 && deferred_error == rrl_none) {
798 }
799
800 /* Advance protocol pointer over leading whitespace, NUL terminate the uri
801 * If non-SP whitespace is encountered, mark as specific error
802 */
803 for (r->protocol = ll; apr_isspace(*r->protocol); ++r->protocol)
804 if (*r->protocol != ' ' && deferred_error == rrl_none)
806 *ll = '\0';
807
808 /* Scan the protocol up to the next whitespace, validation comes later */
809 if (!(ll = (char*) ap_scan_vchar_obstext(r->protocol))) {
810 len = strlen(r->protocol);
811 goto rrl_done;
812 }
813 len = ll - r->protocol;
814
815 /* Advance over trailing whitespace, if found mark in error,
816 * determine if trailing text is found, unconditionally mark in error,
817 * finally NUL terminate the protocol string
818 */
819 if (*ll && !apr_isspace(*ll)) {
821 }
822 else if (strict && *ll) {
824 }
825 else {
826 for ( ; apr_isspace(*ll); ++ll)
827 if (*ll != ' ' && deferred_error == rrl_none)
829 if (*ll && deferred_error == rrl_none)
831 }
832 *((char *)r->protocol + len) = '\0';
833
835 /* For internal integrity and palloc efficiency, reconstruct the_request
836 * in one palloc, using only single SP characters, per spec.
837 */
838 r->the_request = apr_pstrcat(r->pool, r->method, *uri ? " " : NULL, uri,
839 *r->protocol ? " " : NULL, r->protocol, NULL);
840
841 if (len == 8
842 && r->protocol[0] == 'H' && r->protocol[1] == 'T'
843 && r->protocol[2] == 'T' && r->protocol[3] == 'P'
844 && r->protocol[4] == '/' && apr_isdigit(r->protocol[5])
845 && r->protocol[6] == '.' && apr_isdigit(r->protocol[7])
846 && r->protocol[5] != '0') {
847 r->assbackwards = 0;
848 r->proto_num = HTTP_VERSION(r->protocol[5] - '0', r->protocol[7] - '0');
849 }
850 else if (len == 8
851 && (r->protocol[0] == 'H' || r->protocol[0] == 'h')
852 && (r->protocol[1] == 'T' || r->protocol[1] == 't')
853 && (r->protocol[2] == 'T' || r->protocol[2] == 't')
854 && (r->protocol[3] == 'P' || r->protocol[3] == 'p')
855 && r->protocol[4] == '/' && apr_isdigit(r->protocol[5])
856 && r->protocol[6] == '.' && apr_isdigit(r->protocol[7])
857 && r->protocol[5] != '0') {
858 r->assbackwards = 0;
859 r->proto_num = HTTP_VERSION(r->protocol[5] - '0', r->protocol[7] - '0');
860 if (strict && deferred_error == rrl_none)
862 else
863 memcpy((char*)r->protocol, "HTTP", 4);
864 }
865 else if (r->protocol[0]) {
866 r->proto_num = HTTP_VERSION(0, 9);
867 /* Defer setting the r->protocol string till error msg is composed */
870 }
871 else {
872 r->assbackwards = 1;
873 r->protocol = apr_pstrdup(r->pool, "HTTP/0.9");
874 r->proto_num = HTTP_VERSION(0, 9);
875 }
876
877 /* Determine the method_number and parse the uri prior to invoking error
878 * handling, such that these fields are available for substitution
879 */
881 if (r->method_number == M_GET && r->method[0] == 'H')
882 r->header_only = 1;
883
885 if (r->status == HTTP_OK
886 && (r->parsed_uri.path != NULL)
887 && (r->parsed_uri.path[0] != '/')
889 || strcmp(r->parsed_uri.path, "*") != 0)) {
890 /* Invalid request-target per RFC 7230 section 5.3 */
892 }
893
894 /* With the request understood, we can consider HTTP/0.9 specific errors */
895 if (r->proto_num == HTTP_VERSION(0, 9) && deferred_error == rrl_none) {
896 if (conf->http09_enable == AP_HTTP09_DISABLE)
898 else if (strict && (r->method_number != M_GET || r->header_only))
900 }
901
902 /* Now that the method, uri and protocol are all processed,
903 * we can safely resume any deferred error reporting
904 */
905 if (deferred_error != rrl_none) {
908 "HTTP Request Line; Invalid method token: '%.*s'",
912 "HTTP Request Line; Invalid method token: '%.*s'"
913 " (only GET is allowed for HTTP/0.9 requests)",
915 else if (deferred_error == rrl_missinguri)
917 "HTTP Request Line; Missing URI");
918 else if (deferred_error == rrl_baduri)
920 "HTTP Request Line; URI incorrectly encoded: '%.*s'",
924 "HTTP Request Line; Invalid whitespace");
927 "HTTP Request Line; Excess whitespace "
928 "(disallowed by HttpProtocolOptions Strict)");
931 "HTTP Request Line; Extraneous text found '%.*s' "
932 "(perhaps whitespace was injected?)",
934 else if (deferred_error == rrl_reject09)
936 "HTTP Request Line; Rejected HTTP/0.9 request");
939 "HTTP Request Line; Unrecognized protocol '%.*s' "
940 "(perhaps whitespace was injected?)",
943 goto rrl_failed;
944 }
945
947 && r->method_number == M_INVALID) {
949 "HTTP Request Line; Unrecognized HTTP method: '%.*s' "
950 "(disallowed by RegisteredMethods)",
953 /* This can't happen in an HTTP/0.9 request, we verified GET above */
954 return 0;
955 }
956
957 if (r->status != HTTP_OK) {
959 "HTTP Request Line; Unable to parse URI: '%.*s'",
960 field_name_len(r->uri), r->uri);
961 goto rrl_failed;
962 }
963
964 if (strict) {
965 if (r->parsed_uri.fragment) {
966 /* RFC3986 3.5: no fragment */
968 "HTTP Request Line; URI must not contain a fragment");
970 goto rrl_failed;
971 }
974 "HTTP Request Line; URI must not contain a "
975 "username/password");
977 goto rrl_failed;
978 }
979 }
980
981 return 1;
982
984 if (r->proto_num == HTTP_VERSION(0, 9)) {
985 /* Send all parsing and protocol error response with 1.x behavior,
986 * and reserve 505 errors for actual HTTP protocols presented.
987 * As called out in RFC7230 3.5, any errors parsing the protocol
988 * from the request line are nearly always misencoded HTTP/1.x
989 * requests. Only a valid 0.9 request with no parsing errors
990 * at all may be treated as a simple request, if allowed.
991 */
992 r->assbackwards = 0;
994 r->proto_num = HTTP_VERSION(1, 0);
995 r->protocol = apr_pstrdup(r->pool, "HTTP/1.0");
996 }
997 return 0;
998}
999
1001{
1002 core_server_config *conf;
1003 int strict_host_check;
1004 const char *expect;
1005 int access_status;
1006
1008
1009 /* update what we think the virtual host is based on the headers we've
1010 * now read. may update status.
1011 */
1012 strict_host_check = (conf->strict_host_check == AP_CORE_CONFIG_ON);
1013 access_status = ap_update_vhost_from_headers_ex(r, strict_host_check);
1014 if (strict_host_check && access_status != HTTP_OK) {
1015 if (r->server == ap_server_conf) {
1017 "Requested hostname '%s' did not match any ServerName/ServerAlias "
1018 "in the global server configuration ", r->hostname);
1019 }
1020 else {
1022 "Requested hostname '%s' did not match any ServerName/ServerAlias "
1023 "in the matching virtual host (default vhost for "
1024 "current connection is %s:%u)",
1026 }
1028 }
1029 if (r->status != HTTP_OK) {
1030 return 0;
1031 }
1032
1033 if ((!r->hostname && (r->proto_num >= HTTP_VERSION(1, 1)))
1034 || ((r->proto_num == HTTP_VERSION(1, 1))
1035 && !apr_table_get(r->headers_in, "Host"))) {
1036 /*
1037 * Client sent us an HTTP/1.1 or later request without telling us the
1038 * hostname, either with a full URL or a Host: header. We therefore
1039 * need to (as per the 1.1 spec) send an error. As a special case,
1040 * HTTP/1.1 mentions twice (S9, S14.23) that a request MUST contain
1041 * a Host: header, and the server MUST respond with 400 if it doesn't.
1042 */
1044 "client sent HTTP/1.1 request without hostname "
1045 "(see RFC2616 section 14.23): %s", r->uri);
1047 return 0;
1048 }
1049
1050 if (((expect = apr_table_get(r->headers_in, "Expect")) != NULL)
1051 && (expect[0] != '\0')) {
1052 /*
1053 * The Expect header field was added to HTTP/1.1 after RFC 2068
1054 * as a means to signal when a 100 response is desired and,
1055 * unfortunately, to signal a poor man's mandatory extension that
1056 * the server must understand or return 417 Expectation Failed.
1057 */
1058 if (ap_cstr_casecmp(expect, "100-continue") == 0) {
1059 r->expecting_100 = 1;
1060 }
1061 else {
1063 "client sent an unrecognized expectation value "
1064 "of Expect: %s", expect);
1066 return 0;
1067 }
1068 }
1069
1070 return 1;
1071}
1072
1073static int table_do_fn_check_lengths(void *r_, const char *key,
1074 const char *value)
1075{
1076 request_rec *r = r_;
1077 if (value == NULL || r->server->limit_req_fieldsize >= strlen(value) )
1078 return 1;
1079
1081 apr_table_setn(r->notes, "error-notes",
1082 "Size of a request header field exceeds server limit.");
1083 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00560) "Request "
1084 "header exceeds LimitRequestFieldSize after merging: %.*s",
1086 return 0;
1087}
1088
1090{
1091 char *last_field = NULL;
1092 apr_size_t last_len = 0;
1093 apr_size_t alloc_len = 0;
1094 char *field;
1095 char *value;
1097 int fields_read = 0;
1098 char *tmp_field;
1100 int strict = (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE);
1101
1102 /*
1103 * Read header lines until we get the empty separator line, a read error,
1104 * the connection closes (EOF), reach the server limit, or we timeout.
1105 */
1106 while(1) {
1107 apr_status_t rv;
1108
1109 field = NULL;
1111 &len, r, strict ? AP_GETLINE_CRLF : 0, bb);
1112
1113 if (rv != APR_SUCCESS) {
1114 if (APR_STATUS_IS_TIMEUP(rv)) {
1116 }
1117 else {
1119 "Failed to read request header line %s", field);
1121 }
1122
1123 /* ap_rgetline returns APR_ENOSPC if it fills up the buffer before
1124 * finding the end-of-line. This is only going to happen if it
1125 * exceeds the configured limit for a field size.
1126 */
1127 if (rv == APR_ENOSPC) {
1128 apr_table_setn(r->notes, "error-notes",
1129 "Size of a request header field "
1130 "exceeds server limit.");
1132 "Request header exceeds LimitRequestFieldSize%s"
1133 "%.*s",
1134 (field && *field) ? ": " : "",
1135 (field) ? field_name_len(field) : 0,
1136 (field) ? field : "");
1137 }
1138 return;
1139 }
1140
1141 /* For all header values, and all obs-fold lines, the presence of
1142 * additional whitespace is a no-op, so collapse trailing whitespace
1143 * to save buffer allocation and optimize copy operations.
1144 * Do not remove the last single whitespace under any condition.
1145 */
1146 while (len > 1 && (field[len-1] == '\t' || field[len-1] == ' ')) {
1147 field[--len] = '\0';
1148 }
1149
1150 if (*field == '\t' || *field == ' ') {
1151
1152 /* Append any newly-read obs-fold line onto the preceding
1153 * last_field line we are processing
1154 */
1156
1157 if (last_field == NULL) {
1160 "Line folding encountered before first"
1161 " header line");
1162 return;
1163 }
1164
1165 if (field[1] == '\0') {
1168 "Empty folded line encountered");
1169 return;
1170 }
1171
1172 /* Leading whitespace on an obs-fold line can be
1173 * similarly discarded */
1174 while (field[1] == '\t' || field[1] == ' ') {
1175 ++field; --len;
1176 }
1177
1178 /* This line is a continuation of the preceding line(s),
1179 * so append it to the line that we've set aside.
1180 * Note: this uses a power-of-two allocator to avoid
1181 * doing O(n) allocs and using O(n^2) space for
1182 * continuations that span many many lines.
1183 */
1184 fold_len = last_len + len + 1; /* trailing null */
1185
1188 /* report what we have accumulated so far before the
1189 * overflow (last_field) as the field with the problem
1190 */
1191 apr_table_setn(r->notes, "error-notes",
1192 "Size of a request header field "
1193 "exceeds server limit.");
1195 "Request header exceeds LimitRequestFieldSize "
1196 "after folding: %.*s",
1198 return;
1199 }
1200
1201 if (fold_len > alloc_len) {
1202 char *fold_buf;
1203 alloc_len += alloc_len;
1204 if (fold_len > alloc_len) {
1205 alloc_len = fold_len;
1206 }
1207 fold_buf = (char *)apr_palloc(r->pool, alloc_len);
1210 }
1211 memcpy(last_field + last_len, field, len +1); /* +1 for nul */
1212 /* Replace obs-fold w/ SP per RFC 7230 3.2.4 */
1213 last_field[last_len] = ' ';
1214 last_len += len;
1215
1216 /* We've appended this obs-fold line to last_len, proceed to
1217 * read the next input line
1218 */
1219 continue;
1220 }
1221 else if (last_field != NULL) {
1222
1223 /* Process the previous last_field header line with all obs-folded
1224 * segments already concatenated (this is not operating on the
1225 * most recently read input line).
1226 */
1227
1229 && (++fields_read > r->server->limit_req_fields)) {
1231 apr_table_setn(r->notes, "error-notes",
1232 "The number of request header fields "
1233 "exceeds this server's limit.");
1235 "Number of request headers exceeds "
1236 "LimitRequestFields");
1237 return;
1238 }
1239
1240 if (!strict)
1241 {
1242 /* Not Strict ('Unsafe' mode), using the legacy parser */
1243
1244 if (!(value = strchr(last_field, ':'))) { /* Find ':' or */
1245 r->status = HTTP_BAD_REQUEST; /* abort bad request */
1247 "Request header field is missing ':' "
1248 "separator: %.*s", (int)LOG_NAME_MAX_LEN,
1249 last_field);
1250 return;
1251 }
1252
1253 if (value == last_field) {
1256 "Request header field name was empty");
1257 return;
1258 }
1259
1260 *value++ = '\0'; /* NUL-terminate at colon */
1261
1262 if (strpbrk(last_field, "\t\n\v\f\r ")) {
1265 "Request header field name presented"
1266 " invalid whitespace");
1267 return;
1268 }
1269
1270 while (*value == ' ' || *value == '\t') {
1271 ++value; /* Skip to start of value */
1272 }
1273
1274 if (strpbrk(value, "\n\v\f\r")) {
1277 "Request header field value presented"
1278 " bad whitespace");
1279 return;
1280 }
1281 }
1282 else /* Using strict RFC7230 parsing */
1283 {
1284 /* Ensure valid token chars before ':' per RFC 7230 3.2.4 */
1286 if ((value == last_field) || *value != ':') {
1289 "Request header field name is malformed: "
1290 "%.*s", (int)LOG_NAME_MAX_LEN, last_field);
1291 return;
1292 }
1293
1294 *value++ = '\0'; /* NUL-terminate last_field name at ':' */
1295
1296 while (*value == ' ' || *value == '\t') {
1297 ++value; /* Skip LWS of value */
1298 }
1299
1300 /* Find invalid, non-HT ctrl char, or the trailing NULL */
1302
1303 /* Reject value for all garbage input (CTRLs excluding HT)
1304 * e.g. only VCHAR / SP / HT / obs-text are allowed per
1305 * RFC7230 3.2.6 - leave all more explicit rule enforcement
1306 * for specific header handler logic later in the cycle
1307 */
1308 if (*tmp_field != '\0') {
1311 "Request header value is malformed: "
1312 "%.*s", (int)LOG_NAME_MAX_LEN, value);
1313 return;
1314 }
1315 }
1316
1318
1319 /* This last_field header is now stored in headers_in,
1320 * resume processing of the current input line.
1321 */
1322 }
1323
1324 /* Found the terminating empty end-of-headers line, stop. */
1325 if (len == 0) {
1326 break;
1327 }
1328
1329 /* Keep track of this new header line so that we can extend it across
1330 * any obs-fold or parse it on the next loop iteration. We referenced
1331 * our previously allocated buffer in r->headers_in,
1332 * so allocate a fresh buffer if required.
1333 */
1334 alloc_len = 0;
1335 last_field = field;
1336 last_len = len;
1337 }
1338
1339 /* Combine multiple message-header fields with the same
1340 * field-name, following RFC 2616, 4.2.
1341 */
1343
1344 /* enforce LimitRequestFieldSize for merged headers */
1346}
1347
1355
1357{
1358 request_rec *r;
1359 apr_pool_t *p;
1360
1361 apr_pool_create(&p, conn->pool);
1362 apr_pool_tag(p, "request");
1363 r = apr_pcalloc(p, sizeof(request_rec));
1365 r->pool = p;
1366 r->connection = conn;
1367 r->server = conn->base_server;
1368
1369 r->user = NULL;
1370 r->ap_auth_type = NULL;
1371
1373
1374 r->headers_in = apr_table_make(r->pool, 25);
1380 r->notes = apr_table_make(r->pool, 5);
1381
1383 /* Must be set before we run create request hook */
1384
1391
1392 r->sent_bodyct = 0; /* bytect isn't for body */
1393
1394 r->read_length = 0;
1396
1397 r->status = HTTP_OK; /* Until further notice */
1398 r->header_only = 0;
1399 r->the_request = NULL;
1400
1401 /* Begin by presuming any module can make its own path_info assumptions,
1402 * until some module interjects and changes the value.
1403 */
1405
1406 r->useragent_addr = conn->client_addr;
1407 r->useragent_ip = conn->client_ip;
1408
1409 return r;
1410}
1411
1412/* Apply the server's timeout/config to the connection/request. */
1422
1424{
1425 int access_status;
1426 apr_bucket_brigade *tmp_bb;
1427
1429
1431 conn->keepalive = AP_CONN_UNKNOWN;
1432
1434
1435 /* Get the request... */
1436 if (!read_request_line(r, tmp_bb) || !ap_parse_request_line(r)) {
1437 apr_brigade_cleanup(tmp_bb);
1438 switch (r->status) {
1440 case HTTP_BAD_REQUEST:
1445 "request failed: client's request-line exceeds LimitRequestLine (longer than %d)",
1447 }
1448 else if (r->method == NULL) {
1450 "request failed: malformed request line");
1451 }
1453 goto die_unusable_input;
1454
1456 /* Just log, no further action on this connection. */
1458 if (!r->connection->keepalives)
1460 break;
1461 }
1462 /* Not worth dying with. */
1463 conn->keepalive = AP_CONN_CLOSE;
1465 goto ignore;
1466 }
1467 apr_brigade_cleanup(tmp_bb);
1468
1469 /* We may have been in keep_alive_timeout mode, so toggle back
1470 * to the normal timeout mode as we fetch the header lines,
1471 * as necessary.
1472 */
1474
1475 if (!r->assbackwards) {
1476 const char *tenc, *clen;
1477
1478 ap_get_mime_headers_core(r, tmp_bb);
1479 apr_brigade_cleanup(tmp_bb);
1480 if (r->status != HTTP_OK) {
1482 "request failed: error reading the headers");
1484 goto die_unusable_input;
1485 }
1486
1487 clen = apr_table_get(r->headers_in, "Content-Length");
1488 if (clen) {
1489 apr_off_t cl;
1490
1491 if (!ap_parse_strict_length(&cl, clen)) {
1493 "client sent invalid Content-Length "
1494 "(%s): %s", clen, r->uri);
1496 goto die_unusable_input;
1497 }
1498 }
1499
1500 tenc = apr_table_get(r->headers_in, "Transfer-Encoding");
1501 if (tenc) {
1502 /* https://tools.ietf.org/html/rfc7230
1503 * Section 3.3.3.3: "If a Transfer-Encoding header field is
1504 * present in a request and the chunked transfer coding is not
1505 * the final encoding ...; the server MUST respond with the 400
1506 * (Bad Request) status code and then close the connection".
1507 */
1508 if (!ap_is_chunked(r->pool, tenc)) {
1510 "client sent unknown Transfer-Encoding "
1511 "(%s): %s", tenc, r->uri);
1513 goto die_unusable_input;
1514 }
1515
1516 /* https://tools.ietf.org/html/rfc7230
1517 * Section 3.3.3.3: "If a message is received with both a
1518 * Transfer-Encoding and a Content-Length header field, the
1519 * Transfer-Encoding overrides the Content-Length. ... A sender
1520 * MUST remove the received Content-Length field".
1521 */
1522 if (clen) {
1523 apr_table_unset(r->headers_in, "Content-Length");
1524
1525 /* Don't reuse this connection anyway to avoid confusion with
1526 * intermediaries and request/reponse spltting.
1527 */
1528 conn->keepalive = AP_CONN_CLOSE;
1529 }
1530 }
1531 }
1532
1533 /*
1534 * Add the HTTP_IN filter here to ensure that ap_discard_request_body
1535 * called by ap_die and by ap_send_error_response works correctly on
1536 * status codes that do not cause the connection to be dropped and
1537 * in situations where the connection should be kept alive.
1538 */
1540 NULL, r, r->connection);
1541
1542 /* Validate Host/Expect headers and select vhost. */
1543 if (!ap_check_request_header(r)) {
1544 /* we may have switched to another server still */
1547 goto die_before_hooks;
1548 }
1549
1550 /* we may have switched to another server */
1552
1554 goto die;
1555 }
1556
1558 (char *)r->uri, (char *)r->server->defn_name,
1559 r->status);
1560 return r;
1561
1562 /* Everything falls through on failure */
1563
1565 /* Input filters are in an undeterminate state, cleanup (including
1566 * CORE_IN's socket) such that any further attempt to read is EOF.
1567 */
1568 {
1569 ap_filter_t *f = conn->input_filters;
1570 while (f) {
1571 if (f->frec == ap_core_input_filter_handle) {
1572 core_net_rec *net = f->ctx;
1573 apr_brigade_cleanup(net->in_ctx->b);
1574 break;
1575 }
1577 f = f->next;
1578 }
1579 conn->input_filters = r->input_filters = f;
1580 conn->keepalive = AP_CONN_CLOSE;
1581 }
1582
1584 /* First call to ap_die() (non recursive) */
1585 r->status = HTTP_OK;
1586
1587die:
1589
1590 /* ap_die() sent the response through the output filters, we must now
1591 * end the request with an EOR bucket for stream/pipeline accounting.
1592 */
1593 {
1600 }
1601
1602ignore:
1603 r = NULL;
1605 return NULL;
1606}
1607
1609{
1610 int status;
1611
1613 return status;
1614 }
1615
1616 /* Enforce http(s) only scheme for non-forward-proxy requests */
1617 if (!r->proxyreq
1618 && r->parsed_uri.scheme
1619 && (ap_cstr_casecmpn(r->parsed_uri.scheme, "http", 4) != 0
1620 || (r->parsed_uri.scheme[4] != '\0'
1621 && (apr_tolower(r->parsed_uri.scheme[4]) != 's'
1622 || r->parsed_uri.scheme[5] != '\0')))) {
1623 return HTTP_BAD_REQUEST;
1624 }
1625
1626 return OK;
1627}
1628
1629/* if a request with a body creates a subrequest, remove original request's
1630 * input headers which pertain to the body which has already been read.
1631 * out-of-line helper function for ap_set_sub_req_protocol.
1632 */
1633
1635{
1636 apr_table_unset(rnew->headers_in, "Content-Encoding");
1637 apr_table_unset(rnew->headers_in, "Content-Language");
1638 apr_table_unset(rnew->headers_in, "Content-Length");
1639 apr_table_unset(rnew->headers_in, "Content-Location");
1640 apr_table_unset(rnew->headers_in, "Content-MD5");
1641 apr_table_unset(rnew->headers_in, "Content-Range");
1642 apr_table_unset(rnew->headers_in, "Content-Type");
1643 apr_table_unset(rnew->headers_in, "Expires");
1644 apr_table_unset(rnew->headers_in, "Last-Modified");
1645 apr_table_unset(rnew->headers_in, "Transfer-Encoding");
1646}
1647
1648/*
1649 * A couple of other functions which initialize some of the fields of
1650 * a request structure, as appropriate for adjuncts of one kind or another
1651 * to a request in progress. Best here, rather than elsewhere, since
1652 * *someone* has to set the protocol-specific fields...
1653 */
1654
1656 const request_rec *r)
1657{
1658 rnew->the_request = r->the_request; /* Keep original request-line */
1659
1660 rnew->assbackwards = 1; /* Don't send headers from this. */
1661 rnew->no_local_copy = 1; /* Don't try to send HTTP_NOT_MODIFIED for a
1662 * fragment. */
1663 rnew->method = "GET";
1664 rnew->method_number = M_GET;
1665 rnew->protocol = "INCLUDED";
1666
1667 rnew->status = HTTP_OK;
1668
1669 rnew->headers_in = apr_table_copy(rnew->pool, r->headers_in);
1670 rnew->trailers_in = apr_table_copy(rnew->pool, r->trailers_in);
1671
1672 /* did the original request have a body? (e.g. POST w/SSI tags)
1673 * if so, make sure the subrequest doesn't inherit body headers
1674 */
1675 if (!r->kept_body && (apr_table_get(r->headers_in, "Content-Length")
1676 || apr_table_get(r->headers_in, "Transfer-Encoding"))) {
1678 }
1680 rnew->headers_out = apr_table_make(rnew->pool, 5);
1681 rnew->err_headers_out = apr_table_make(rnew->pool, 5);
1682 rnew->trailers_out = apr_table_make(rnew->pool, 5);
1683 rnew->notes = apr_table_make(rnew->pool, 5);
1684
1685 rnew->expecting_100 = r->expecting_100;
1686 rnew->read_length = r->read_length;
1687 rnew->read_body = REQUEST_NO_BODY;
1688
1689 rnew->main = (request_rec *) r;
1690}
1691
1693{
1694 conn_rec *c = r->connection;
1696 apr_bucket *b;
1697
1698 bb = apr_brigade_create(r->pool, c->bucket_alloc);
1699 if (status != OK) {
1700 b = ap_bucket_error_create(status, NULL, r->pool, c->bucket_alloc);
1702 }
1703 b = apr_bucket_eos_create(c->bucket_alloc);
1705
1708}
1709
1711{
1712 /* tell the filter chain there is no more content coming */
1713 if (!sub->eos_sent) {
1714 end_output_stream(sub, OK);
1715 }
1716}
1717
1718/* finalize_request_protocol is called at completion of sending the
1719 * response. Its sole purpose is to send the terminating protocol
1720 * information for any wrappers around the response message body
1721 * (i.e., transfer encodings). It should have been named finalize_response.
1722 */
1724{
1726
1727 /* tell the filter chain there is no more content coming */
1728 if (!r->eos_sent) {
1730 }
1731}
1732
1733/*
1734 * Support for the Basic authentication protocol, and a bit for Digest.
1735 */
1737{
1738 const char *type = ap_auth_type(r);
1739 if (type) {
1741 }
1742 else {
1744 "need AuthType to note auth failure: %s", r->uri);
1745 }
1746}
1747
1752
1757
1759{
1760 const char *auth_line = apr_table_get(r->headers_in,
1762 ? "Proxy-Authorization"
1763 : "Authorization");
1764 const char *t;
1765
1766 if (!(t = ap_auth_type(r)) || ap_cstr_casecmp(t, "Basic"))
1767 return DECLINED;
1768
1769 if (!ap_auth_name(r)) {
1771 "need AuthName: %s", r->uri);
1773 }
1774
1775 if (!auth_line) {
1777 return HTTP_UNAUTHORIZED;
1778 }
1779
1780 if (ap_cstr_casecmp(ap_getword(r->pool, &auth_line, ' '), "Basic")) {
1781 /* Client tried to authenticate using wrong auth scheme */
1783 "client used wrong authentication scheme: %s", r->uri);
1785 return HTTP_UNAUTHORIZED;
1786 }
1787
1788 while (*auth_line == ' ' || *auth_line == '\t') {
1789 auth_line++;
1790 }
1791
1793 r->user = ap_getword_nulls (r->pool, &t, ':');
1795 r->ap_auth_type = "Basic";
1796
1797 *pw = t;
1798
1799 return OK;
1800}
1801
1803 const char **username,
1804 const char **password)
1805{
1806 const char *auth_header;
1807 const char *credentials;
1808 const char *decoded;
1809 const char *user;
1810
1811 auth_header = (PROXYREQ_PROXY == r->proxyreq) ? "Proxy-Authorization"
1812 : "Authorization";
1814
1815 if (!credentials) {
1816 /* No auth header. */
1817 return APR_EINVAL;
1818 }
1819
1820 if (ap_cstr_casecmp(ap_getword(r->pool, &credentials, ' '), "Basic")) {
1821 /* These aren't Basic credentials. */
1822 return APR_EINVAL;
1823 }
1824
1825 while (*credentials == ' ' || *credentials == '\t') {
1826 credentials++;
1827 }
1828
1829 /* XXX Our base64 decoding functions don't actually error out if the string
1830 * we give it isn't base64; they'll just silently stop and hand us whatever
1831 * they've parsed up to that point.
1832 *
1833 * Since this function is supposed to be a drop-in replacement for the
1834 * deprecated ap_get_basic_auth_pw(), don't fix this for 2.4.x.
1835 */
1837 user = ap_getword_nulls(r->pool, &decoded, ':');
1838
1839 if (username) {
1840 *username = user;
1841 }
1842 if (password) {
1843 *password = decoded;
1844 }
1845
1846 return APR_SUCCESS;
1847}
1848
1850 int data_sent; /* true if the C-L filter has already sent at
1851 * least one bucket on to the next output filter
1852 * for this request
1853 */
1855};
1856
1857/* This filter computes the content length, but it also computes the number
1858 * of bytes sent to the client. This means that this filter will always run
1859 * through all of the buckets in all brigades
1860 */
1862 ap_filter_t *f,
1864{
1865 request_rec *r = f->r;
1866 struct content_length_ctx *ctx;
1867 apr_bucket *e;
1868 int eos = 0;
1870
1871 ctx = f->ctx;
1872 if (!ctx) {
1873 f->ctx = ctx = apr_palloc(r->pool, sizeof(*ctx));
1874 ctx->data_sent = 0;
1876 }
1877
1878 /* Loop through the brigade to count the length. To avoid
1879 * arbitrary memory consumption with morphing bucket types, this
1880 * loop will stop and pass on the brigade when necessary. */
1882 while (e != APR_BRIGADE_SENTINEL(b)) {
1883 apr_status_t rv;
1884
1885 if (APR_BUCKET_IS_EOS(e)) {
1886 eos = 1;
1887 break;
1888 }
1889 /* For a flush bucket, fall through to pass the brigade and
1890 * flush now. */
1891 else if (APR_BUCKET_IS_FLUSH(e)) {
1892 e = APR_BUCKET_NEXT(e);
1893 }
1894 /* For metadata bucket types other than FLUSH, loop. */
1895 else if (APR_BUCKET_IS_METADATA(e)) {
1896 e = APR_BUCKET_NEXT(e);
1897 continue;
1898 }
1899 /* For determinate length data buckets, count the length and
1900 * continue. */
1901 else if (e->length != (apr_size_t)-1) {
1902 r->bytes_sent += e->length;
1903 e = APR_BUCKET_NEXT(e);
1904 continue;
1905 }
1906 /* For indeterminate length data buckets, perform one read. */
1907 else /* e->length == (apr_size_t)-1 */ {
1909 const char *ignored;
1910
1911 rv = apr_bucket_read(e, &ignored, &len, eblock);
1912 if ((rv != APR_SUCCESS) && !APR_STATUS_IS_EAGAIN(rv)) {
1914 "ap_content_length_filter: "
1915 "apr_bucket_read() failed");
1916 return rv;
1917 }
1918 if (rv == APR_SUCCESS) {
1920 e = APR_BUCKET_NEXT(e);
1921 r->bytes_sent += len;
1922 }
1923 else if (APR_STATUS_IS_EAGAIN(rv)) {
1925
1926 /* Next read must block. */
1928
1929 /* Ensure the last bucket to pass down is a flush if
1930 * the next read will block. */
1931 flush = apr_bucket_flush_create(f->c->bucket_alloc);
1933 }
1934 }
1935
1936 /* Optimization: if the next bucket is EOS (directly after a
1937 * bucket morphed to the heap, or a flush), short-cut to
1938 * handle EOS straight away - allowing C-L to be determined
1939 * for content which is already entirely in memory. */
1941 continue;
1942 }
1943
1944 /* On reaching here, pass on everything in the brigade up to
1945 * this point. */
1946 apr_brigade_split_ex(b, e, ctx->tmpbb);
1947
1948 rv = ap_pass_brigade(f->next, b);
1949 if (rv != APR_SUCCESS) {
1950 return rv;
1951 }
1952 else if (f->c->aborted) {
1953 return APR_ECONNABORTED;
1954 }
1956 APR_BRIGADE_CONCAT(b, ctx->tmpbb);
1958
1959 ctx->data_sent = 1;
1960 }
1961
1962 /* If we've now seen the entire response and it's otherwise
1963 * okay to set the C-L in the response header, then do so now.
1964 *
1965 * We can only set a C-L in the response header if we haven't already
1966 * sent any buckets on to the next output filter for this request.
1967 */
1968 if (ctx->data_sent == 0 && eos &&
1969 /* don't whack the C-L if it has already been set for a HEAD
1970 * by something like proxy. the brigade only has an EOS bucket
1971 * in this case, making r->bytes_sent zero.
1972 *
1973 * if r->bytes_sent > 0 we have a (temporary) body whose length may
1974 * have been changed by a filter. the C-L header might not have been
1975 * updated so we do it here. long term it would be cleaner to have
1976 * such filters update or remove the C-L header, and just use it
1977 * if present.
1978 */
1980 apr_table_get(r->headers_out, "Content-Length"))) {
1982 }
1983
1984 ctx->data_sent = 1;
1985 return ap_pass_brigade(f->next, b);
1986}
1987
1988/*
1989 * Send the body of a response to the client.
1990 */
1994{
1995 conn_rec *c = r->connection;
1997 apr_status_t rv;
1998
1999 bb = apr_brigade_create(r->pool, c->bucket_alloc);
2000
2002
2003 rv = ap_pass_brigade(r->output_filters, bb);
2004 if (rv != APR_SUCCESS) {
2005 *nbytes = 0; /* no way to tell how many were actually sent */
2006 }
2007 else {
2008 *nbytes = len;
2009 }
2010
2011 return rv;
2012}
2013
2014#if APR_HAS_MMAP
2015/* send data from an in-memory buffer */
2017 request_rec *r,
2020{
2021 conn_rec *c = r->connection;
2023 apr_bucket *b;
2024
2025 bb = apr_brigade_create(r->pool, c->bucket_alloc);
2026 b = apr_bucket_mmap_create(mm, offset, length, c->bucket_alloc);
2029
2030 return mm->size; /* XXX - change API to report apr_status_t? */
2031}
2032#endif /* APR_HAS_MMAP */
2033
2038
2041{
2042 old_write_filter_ctx *ctx = f->ctx;
2043
2045
2046 if (ctx->bb != NULL) {
2047 /* whatever is coming down the pipe (we don't care), we
2048 * can simply insert our buffered data at the front and
2049 * pass the whole bundle down the chain.
2050 */
2051 APR_BRIGADE_PREPEND(bb, ctx->bb);
2052 }
2053
2054 return ap_pass_brigade(f->next, bb);
2055}
2056
2058{
2059 ap_filter_t *f;
2061
2062 /* future optimization: record some flags in the request_rec to
2063 * say whether we've added our filter, and whether it is first.
2064 */
2065
2066 /* this will typically exit on the first test */
2067 for (f = r->output_filters; f != NULL; f = f->next) {
2068 if (ap_old_write_func == f->frec)
2069 break;
2070 }
2071
2072 if (f == NULL) {
2073 /* our filter hasn't been added yet */
2074 ctx = apr_pcalloc(r->pool, sizeof(*ctx));
2076
2077 ap_add_output_filter("OLD_WRITE", ctx, r, r->connection);
2078 f = r->output_filters;
2079 }
2080
2081 return f;
2082}
2083
2085 const char *str, apr_size_t len)
2086{
2087 conn_rec *c = r->connection;
2088 ap_filter_t *f;
2090
2091 if (len == 0)
2092 return APR_SUCCESS;
2093
2095 ctx = f->ctx;
2096
2097 /* if the first filter is not our buffering filter, then we have to
2098 * deliver the content through the normal filter chain
2099 */
2100 if (f != r->output_filters) {
2101 apr_status_t rv;
2102 apr_bucket *b = apr_bucket_transient_create(str, len, c->bucket_alloc);
2103 APR_BRIGADE_INSERT_TAIL(ctx->tmpbb, b);
2104
2105 rv = ap_pass_brigade(r->output_filters, ctx->tmpbb);
2106 apr_brigade_cleanup(ctx->tmpbb);
2107 return rv;
2108 }
2109
2110 if (ctx->bb == NULL) {
2111 ctx->bb = apr_brigade_create(r->pool, c->bucket_alloc);
2112 }
2113
2114 return ap_fwrite(f->next, ctx->bb, str, len);
2115}
2116
2118{
2119 char c2 = (char)c;
2120
2121 if (r->connection->aborted) {
2122 return -1;
2123 }
2124
2125 if (buffer_output(r, &c2, 1) != APR_SUCCESS)
2126 return -1;
2127
2128 return c;
2129}
2130
2131AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r)
2132{
2133 if (nbyte < 0)
2134 return -1;
2135
2136 if (r->connection->aborted)
2137 return -1;
2138
2140 return -1;
2141
2142 return nbyte;
2143}
2144
2150
2151/* Flush callback for apr_vformatter; returns -1 on error. */
2153{
2154 /* callback function passed to ap_vformatter to be called when
2155 * vformatter needs to write into buff and buff.curpos > buff.endpos */
2156
2157 /* ap_vrprintf_data passed as a apr_vformatter_buff_t, which is then
2158 * "downcast" to an ap_vrprintf_data */
2159 struct ap_vrprintf_data *vd = (struct ap_vrprintf_data*)buff;
2160
2161 if (vd->r->connection->aborted)
2162 return -1;
2163
2164 /* r_flush is called when vbuff is completely full */
2165 if (buffer_output(vd->r, vd->buff, AP_IOBUFSIZE)) {
2166 return -1;
2167 }
2168
2169 /* reset the buffer position */
2170 vd->vbuff.curpos = vd->buff;
2171 vd->vbuff.endpos = vd->buff + AP_IOBUFSIZE;
2172
2173 return 0;
2174}
2175
2177{
2178 int written;
2179 struct ap_vrprintf_data vd;
2181
2183 vd.vbuff.endpos = vrprintf_buf + AP_IOBUFSIZE;
2184 vd.r = r;
2185 vd.buff = vrprintf_buf;
2186
2187 if (r->connection->aborted)
2188 return -1;
2189
2190 written = apr_vformatter(r_flush, &vd.vbuff, fmt, va);
2191
2192 if (written != -1) {
2193 int n = vd.vbuff.curpos - vrprintf_buf;
2194
2195 /* last call to buffer_output, to finish clearing the buffer */
2197 return -1;
2198
2199 written += n;
2200 }
2201
2202 return written;
2203}
2204
2206{
2207 va_list va;
2208 int n;
2209
2210 if (r->connection->aborted)
2211 return -1;
2212
2213 va_start(va, fmt);
2214 n = ap_vrprintf(r, fmt, va);
2215 va_end(va);
2216
2217 return n;
2218}
2219
2221{
2222 va_list va;
2223 const char *s;
2225 apr_size_t written = 0;
2226
2227 if (r->connection->aborted)
2228 return -1;
2229
2230 /* ### TODO: if the total output is large, put all the strings
2231 * ### into a single brigade, rather than flushing each time we
2232 * ### fill the buffer
2233 */
2234 va_start(va, r);
2235 while (1) {
2236 s = va_arg(va, const char *);
2237 if (s == NULL)
2238 break;
2239
2240 len = strlen(s);
2241 if (buffer_output(r, s, len) != APR_SUCCESS) {
2242 va_end(va);
2243 return -1;
2244 }
2245
2246 written += len;
2247 }
2248 va_end(va);
2249
2250 return written;
2251}
2252
2254{
2255 conn_rec *c = r->connection;
2256 apr_bucket *b;
2257 ap_filter_t *f;
2259 apr_status_t rv;
2260
2262 ctx = f->ctx;
2263
2264 b = apr_bucket_flush_create(c->bucket_alloc);
2265 APR_BRIGADE_INSERT_TAIL(ctx->tmpbb, b);
2266
2267 rv = ap_pass_brigade(r->output_filters, ctx->tmpbb);
2268 apr_brigade_cleanup(ctx->tmpbb);
2269 if (rv != APR_SUCCESS)
2270 return -1;
2271
2272 return 0;
2273}
2274
2275/*
2276 * This function sets the Last-Modified output header field to the value
2277 * of the mtime field in the request structure - rationalized to keep it from
2278 * being in the future.
2279 */
2290
2295
2296#if APR_CHARSET_EBCDIC
2297static int send_header(void *data, const char *key, const char *val)
2298{
2299 char *header_line = NULL;
2300 hdr_ptr *hdr = (hdr_ptr*)data;
2301
2302 header_line = apr_pstrcat(hdr->bb->p, key, ": ", val, CRLF, NULL);
2304 ap_fputs(hdr->f, hdr->bb, header_line);
2305 return 1;
2306}
2307#else
2308static int send_header(void *data, const char *key, const char *val)
2309{
2310 ap_fputstrs(((hdr_ptr*)data)->f, ((hdr_ptr*)data)->bb,
2311 key, ": ", val, CRLF, NULL);
2312 return 1;
2313 }
2314#endif
2315
2317{
2318 hdr_ptr x;
2319 char *response_line = NULL;
2320 const char *status_line;
2321 request_rec *rr;
2322
2323 if (r->proto_num < HTTP_VERSION(1,1)) {
2324 /* don't send interim response to HTTP/1.0 Client */
2325 return;
2326 }
2327 if (!ap_is_HTTP_INFO(r->status)) {
2329 "Status is %d - not sending interim response", r->status);
2330 return;
2331 }
2332 if (r->status == HTTP_CONTINUE) {
2333 if (!r->expecting_100) {
2334 /*
2335 * Don't send 100-Continue when there was no Expect: 100-continue
2336 * in the request headers. For origin servers this is a SHOULD NOT
2337 * for proxies it is a MUST NOT according to RFC 2616 8.2.3
2338 */
2339 return;
2340 }
2341
2342 /* if we send an interim response, we're no longer in a state of
2343 * expecting one. Also, this could feasibly be in a subrequest,
2344 * so we need to propagate the fact that we responded.
2345 */
2346 for (rr = r; rr != NULL; rr = rr->main) {
2347 rr->expecting_100 = 0;
2348 }
2349 }
2350
2351 status_line = r->status_line;
2352 if (status_line == NULL) {
2353 status_line = ap_get_status_line_ex(r->pool, r->status);
2354 }
2356 AP_SERVER_PROTOCOL " ", status_line, CRLF,
2357 NULL);
2359
2362
2363 ap_fputs(x.f, x.bb, response_line);
2364 if (send_headers) {
2367 }
2368 ap_fputs(x.f, x.bb, CRLF_ASCII);
2369 ap_fflush(x.f, x.bb);
2371}
2372
2373/*
2374 * Compare two protocol identifier. Result is similar to strcmp():
2375 * 0 gives same precedence, >0 means proto1 is preferred.
2376 */
2378 const char *proto1,
2379 const char *proto2)
2380{
2381 if (preferences && preferences->nelts > 0) {
2384 if (index2 > index1) {
2385 return (index1 >= 0) ? 1 : -1;
2386 }
2387 else if (index1 > index2) {
2388 return (index2 >= 0) ? -1 : 1;
2389 }
2390 }
2391 /* both have the same index (maybe -1 or no pref configured) and we compare
2392 * the names so that spdy3 gets precedence over spdy2. That makes
2393 * the outcome at least deterministic. */
2394 return strcmp(proto1, proto2);
2395}
2396
2398{
2399 const char *protocol = ap_run_protocol_get(c);
2401}
2402
2404 server_rec *s, int report_all,
2406{
2407 apr_pool_t *pool = r? r->pool : c->pool;
2408 core_server_config *conf;
2409 const char *existing;
2411
2412 if (!s) {
2413 s = (r? r->server : c->base_server);
2414 }
2415 conf = ap_get_core_module_config(s->module_config);
2416
2417 if (conf->protocols->nelts > 0) {
2419 if (conf->protocols->nelts > 1
2421 int i;
2422
2423 /* possibly more than one choice or one, but not the
2424 * existing. (TODO: maybe 426 and Upgrade then?) */
2426 sizeof(char *));
2427 for (i = 0; i < conf->protocols->nelts; i++) {
2428 const char *p = APR_ARRAY_IDX(conf->protocols, i, char *);
2429 if (strcmp(existing, p)) {
2430 /* not the one we have and possible, add in this order */
2431 APR_ARRAY_PUSH(upgrades, const char*) = p;
2432 }
2433 else if (!report_all) {
2434 break;
2435 }
2436 }
2437 }
2438 }
2439
2441 return APR_SUCCESS;
2442}
2443
2445 server_rec *s,
2447{
2448 apr_pool_t *pool = r? r->pool : c->pool;
2449 core_server_config *conf;
2450 const char *protocol = NULL, *existing;
2452
2453 if (!s) {
2454 s = (r? r->server : c->base_server);
2455 }
2456 conf = ap_get_core_module_config(s->module_config);
2457
2458 if (APLOGcdebug(c)) {
2459 const char *p = apr_array_pstrcat(pool, conf->protocols, ',');
2461 "select protocol from %s, choices=%s for server %s",
2463 s->server_hostname);
2464 }
2465
2466 if (conf->protocols->nelts <= 0) {
2467 /* nothing configured, by default, we only allow http/1.1 here.
2468 * For now...
2469 */
2471 return AP_PROTOCOL_HTTP1;
2472 }
2473 else {
2474 return NULL;
2475 }
2476 }
2477
2478 proposals = apr_array_make(pool, choices->nelts + 1, sizeof(char *));
2480
2481 /* If the existing protocol has not been proposed, but is a choice,
2482 * add it to the proposals implicitly.
2483 */
2487 APR_ARRAY_PUSH(proposals, const char*) = existing;
2488 }
2489
2490 if (proposals->nelts > 0) {
2491 int i;
2492 const apr_array_header_t *prefs = NULL;
2493
2494 /* Default for protocols_honor_order is 'on' or != 0 */
2495 if (conf->protocols_honor_order == 0 && choices->nelts > 0) {
2496 prefs = choices;
2497 }
2498 else {
2499 prefs = conf->protocols;
2500 }
2501
2502 /* Select the most preferred protocol */
2503 if (APLOGcdebug(c)) {
2505 "select protocol, proposals=%s preferences=%s configured=%s",
2508 apr_array_pstrcat(pool, conf->protocols, ','));
2509 }
2510 for (i = 0; i < proposals->nelts; ++i) {
2511 const char *p = APR_ARRAY_IDX(proposals, i, const char *);
2512 if (!ap_array_str_contains(conf->protocols, p)) {
2513 /* not a configured protocol here */
2514 continue;
2515 }
2516 else if (!protocol
2517 || (protocol_cmp(prefs, protocol, p) < 0)) {
2518 /* none selected yet or this one has preference */
2519 protocol = p;
2520 }
2521 }
2522 }
2523 if (APLOGcdebug(c)) {
2525 "selected protocol=%s",
2526 protocol? protocol : "(none)");
2527 }
2528
2529 return protocol;
2530}
2531
2533 server_rec *s,
2534 const char *protocol)
2535{
2536 const char *current = ap_get_protocol(c);
2537 int rc;
2538
2539 if (!strcmp(current, protocol)) {
2541 "already at it, protocol_switch to %s",
2542 protocol);
2543 return APR_SUCCESS;
2544 }
2545
2547 switch (rc) {
2548 case DECLINED:
2550 "no implementation for protocol_switch to %s",
2551 protocol);
2552 return APR_ENOTIMPL;
2553 case OK:
2554 case DONE:
2555 return APR_SUCCESS;
2556 default:
2558 "unexpected return code %d from protocol_switch to %s"
2559 , rc, protocol);
2560 return APR_EOF;
2561 }
2562}
2563
2565 server_rec *s, const char *protocol)
2566{
2567 core_server_config *conf;
2568
2569 if (!s) {
2570 s = (r? r->server : c->base_server);
2571 }
2572 conf = ap_get_core_module_config(s->module_config);
2573
2574 if (conf->protocols->nelts > 0) {
2576 }
2578}
2579
2580
2582 (request_rec *r, conn_rec *c),
2583 (r, c))
2589 (const request_rec *r), (r), NULL)
2590AP_IMPLEMENT_HOOK_RUN_FIRST(unsigned short,default_port,
2591 (const request_rec *r), (r), 0)
2593 (request_rec *r, const char *auth_type),
2602 const char *protocol),
Symbol export macros and hook functions.
#define AP_DECLARE_DATA
Definition ap_config.h:89
#define AP_DECLARE_NONSTD(type)
Definition ap_config.h:77
#define AP_DECLARE(type)
Definition ap_config.h:67
#define AP_IMPLEMENT_HOOK_VOID(name, args_decl, args_use)
Definition ap_hooks.h:94
#define AP_IMPLEMENT_HOOK_RUN_ALL(ret, name, args_decl, args_use, ok, decline)
Definition ap_hooks.h:117
#define AP_IMPLEMENT_HOOK_RUN_FIRST(ret, name, args_decl, args_use, decline)
Definition ap_hooks.h:137
int n
Definition ap_regex.h:278
const char * buff
Definition ap_regex.h:186
const char apr_size_t len
Definition ap_regex.h:187
#define AP_READ_REQUEST_SUCCESS(arg0, arg1, arg2, arg3, arg4)
#define AP_READ_REQUEST_FAILURE(arg0)
#define AP_READ_REQUEST_ENTRY(arg0, arg1)
APR-UTIL Buckets/Bucket Brigades.
APR general purpose library routines.
APR Signal Handling.
APR Strings library.
APR-UTIL string matching routines.
APR Standard Headers Support.
ap_conf_vector_t * ap_create_request_config(apr_pool_t *p)
Definition config.c:356
request_rec * r
void * csd
int flush
#define DEFAULT_LIMIT_BLANK_LINES
Definition httpd.h:206
#define ap_http_scheme(r)
Definition httpd.h:297
#define AP_IOBUFSIZE
Definition httpd.h:306
#define AP_SERVER_PROTOCOL
Definition httpd.h:216
#define DECLINED
Definition httpd.h:457
#define HTTP_VERSION(major, minor)
Definition httpd.h:269
#define AP_CORE_DECLARE
Definition httpd.h:381
#define OK
Definition httpd.h:456
#define DONE
Definition httpd.h:458
#define AP_CORE_DECLARE_NONSTD
Definition httpd.h:390
#define ap_xlate_proto_to_ascii(x, y)
Definition util_ebcdic.h:80
#define ap_xlate_proto_from_ascii(x, y)
Definition util_ebcdic.h:81
#define ap_fwrite(f, bb, data, nbyte)
apr_status_t ap_fflush(ap_filter_t *f, apr_bucket_brigade *bb)
void ap_remove_input_filter(ap_filter_t *f)
#define ap_fputs(f, bb, str)
apr_status_t ap_pass_brigade(ap_filter_t *filter, apr_bucket_brigade *bucket)
ap_filter_t * ap_add_input_filter_handle(ap_filter_rec_t *f, void *ctx, request_rec *r, conn_rec *c)
ap_filter_t * ap_add_output_filter(const char *name, void *ctx, request_rec *r, conn_rec *c)
apr_status_t ap_fputstrs(ap_filter_t *f, apr_bucket_brigade *bb,...)
apr_status_t ap_get_brigade(ap_filter_t *filter, apr_bucket_brigade *bucket, ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes)
#define ap_get_core_module_config(v)
Definition http_core.h:383
const char * ap_auth_name(request_rec *r)
Definition core.c:807
apr_socket_t * ap_get_conn_socket(conn_rec *c)
Definition core.c:5202
const char * ap_auth_type(request_rec *r)
Definition core.c:793
#define AP_CORE_CONFIG_ON
Definition http_core.h:505
ap_filter_rec_t * ap_core_input_filter_handle
Definition core.c:134
#define APLOGNO(n)
Definition http_log.h:117
#define APLOGcdebug(c)
Definition http_log.h:256
#define APLOG_INFO
Definition http_log.h:70
#define APLOGrtrace5(r)
Definition http_log.h:250
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_ERR
Definition http_log.h:67
#define ap_log_cerror
Definition http_log.h:498
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_WARNING
Definition http_log.h:68
#define ap_log_data
Definition http_log.h:604
#define APLOG_TRACE5
Definition http_log.h:76
#define APLOG_DEBUG
Definition http_log.h:71
server_rec * ap_server_conf
Definition config.c:62
const unsigned char * buf
Definition util_md5.h:50
int ap_rflush(request_rec *r)
Definition protocol.c:2253
int ap_run_protocol_switch(conn_rec *c, request_rec *r, server_rec *s, const char *protocol)
Definition protocol.c:2603
int ap_method_number_of(const char *method)
int ap_parse_request_line(request_rec *r)
Definition protocol.c:721
void ap_finalize_sub_req_protocol(request_rec *sub)
Definition protocol.c:1710
void ap_setup_make_content_type(apr_pool_t *pool)
Definition protocol.c:87
#define AP_GETLINE_FOLD
int ap_rvputs(request_rec *r,...)
Definition protocol.c:2220
int ap_run_protocol_propose(conn_rec *c, request_rec *r, server_rec *s, const apr_array_header_t *offers, apr_array_header_t *proposals)
Definition protocol.c:2599
apr_status_t ap_get_protocol_upgrades(conn_rec *c, request_rec *r, server_rec *s, int report_all, const apr_array_header_t **pupgrades)
Definition protocol.c:2403
void ap_run_pre_read_request(request_rec *r, conn_rec *c)
Definition protocol.c:2583
#define AP_GETLINE_CRLF
int ap_run_post_read_request(request_rec *r)
Definition protocol.c:2585
#define AP_GET_BASIC_AUTH_PW_NOTE
ap_method_list_t * ap_make_method_list(apr_pool_t *p, int nelts)
void ap_send_interim_response(request_rec *r, int send_headers)
Definition protocol.c:2316
void ap_parse_uri(request_rec *r, const char *uri)
Definition protocol.c:580
const char * ap_run_protocol_get(const conn_rec *c)
Definition protocol.c:2605
apr_time_t ap_rationalize_mtime(request_rec *r, apr_time_t mtime)
Definition protocol.c:174
void ap_note_digest_auth_failure(request_rec *r)
Definition protocol.c:1753
#define AP_GETLINE_NOSPC_EOL
void ap_finalize_request_protocol(request_rec *r)
Definition protocol.c:1723
void ap_note_auth_failure(request_rec *r)
Definition protocol.c:1736
#define ap_rgetline(s, n, read, r, fold, bb)
int ap_get_basic_auth_pw(request_rec *r, const char **pw)
Definition protocol.c:1758
void ap_note_basic_auth_failure(request_rec *r)
Definition protocol.c:1748
void ap_set_sub_req_protocol(request_rec *rnew, const request_rec *r)
Definition protocol.c:1655
const char * ap_get_status_line_ex(apr_pool_t *p, int status)
apr_status_t ap_get_basic_auth_components(const request_rec *r, const char **username, const char **password)
Definition protocol.c:1802
request_rec * ap_create_request(conn_rec *conn)
Definition protocol.c:1356
int ap_post_read_request(request_rec *r)
Definition protocol.c:1608
void ap_set_content_length(request_rec *r, apr_off_t clength)
Definition protocol.c:160
int ap_run_note_auth_failure(request_rec *r, const char *auth_type)
Definition protocol.c:2594
apr_status_t ap_switch_protocol(conn_rec *c, request_rec *r, server_rec *s, const char *protocol)
Definition protocol.c:2532
request_rec * ap_read_request(conn_rec *conn)
Definition protocol.c:1423
const char * ap_get_protocol(conn_rec *c)
Definition protocol.c:2397
const char * ap_select_protocol(conn_rec *c, request_rec *r, server_rec *s, const apr_array_header_t *choices)
Definition protocol.c:2444
int ap_rputc(int c, request_rec *r)
Definition protocol.c:2117
void ap_set_last_modified(request_rec *r)
Definition protocol.c:2280
const char * ap_make_content_type(request_rec *r, const char *type)
Definition protocol.c:110
int ap_run_log_transaction(request_rec *r)
Definition protocol.c:2587
void ap_get_mime_headers_core(request_rec *r, apr_bucket_brigade *bb)
Definition protocol.c:1089
int ap_check_request_header(request_rec *r)
Definition protocol.c:1000
int ap_getline(char *s, int n, request_rec *r, int flags)
Definition protocol.c:545
apr_status_t ap_content_length_filter(ap_filter_t *f, apr_bucket_brigade *b)
Definition protocol.c:1861
int ap_rwrite(const void *buf, int nbyte, request_rec *r)
Definition protocol.c:2131
int ap_is_allowed_protocol(conn_rec *c, request_rec *r, server_rec *s, const char *protocol)
Definition protocol.c:2564
int ap_discard_request_body(request_rec *r)
apr_status_t ap_rgetline_core(char **s, apr_size_t n, apr_size_t *read, request_rec *r, int flags, apr_bucket_brigade *bb)
Definition protocol.c:216
int ap_vrprintf(request_rec *r, const char *fmt, va_list va)
Definition protocol.c:2176
ap_filter_rec_t * ap_old_write_func
Definition protocol.c:75
apr_status_t ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset, apr_size_t len, apr_size_t *nbytes)
Definition protocol.c:1991
apr_status_t ap_old_write_filter(ap_filter_t *f, apr_bucket_brigade *bb)
Definition protocol.c:2039
void ap_get_mime_headers(request_rec *r)
Definition protocol.c:1348
#define AP_PROTOCOL_HTTP1
apr_bucket * ap_bucket_error_create(int error, const char *buf, apr_pool_t *p, apr_bucket_alloc_t *list)
apr_bucket * ap_bucket_eor_create(apr_bucket_alloc_t *list, request_rec *r)
Definition eor_bucket.c:68
int ap_run_create_request(request_rec *r)
Definition request.c:98
void ap_die(int type, request_rec *r)
#define CRLF_ASCII
Definition httpd.h:737
#define CRLF
Definition httpd.h:724
#define APR_EGENERAL
Definition apr_errno.h:313
#define APR_ENOSPC
Definition apr_errno.h:676
#define APR_EOF
Definition apr_errno.h:461
#define APR_BADARG
Definition apr_errno.h:459
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_ECONNABORTED
Definition apr_errno.h:769
#define APR_EINVAL
Definition apr_errno.h:711
#define APR_STATUS_IS_EINVAL(s)
Definition apr_errno.h:1266
#define APR_STATUS_IS_ENOSPC(s)
Definition apr_errno.h:1255
#define APR_STATUS_IS_TIMEUP(s)
Definition apr_errno.h:534
#define APR_STATUS_IS_EAGAIN(s)
Definition apr_errno.h:1272
apr_file_t * f
apr_brigade_flush void const char apr_size_t nbyte
#define APR_BUCKET_IS_FLUSH(e)
#define APR_BUCKET_IS_METADATA(e)
#define APR_BRIGADE_PREPEND(a, b)
#define APR_BRIGADE_INSERT_TAIL(b, e)
#define APR_BUCKET_NEXT(e)
apr_read_type_e
Definition apr_buckets.h:57
apr_bucket * e
#define APR_BRIGADE_CONCAT(a, b)
#define APR_BRIGADE_EMPTY(b)
#define APR_BRIGADE_SENTINEL(b)
#define APR_BUCKET_IS_EOS(e)
apr_brigade_flush void * ctx
#define APR_BRIGADE_FIRST(b)
#define APR_BUCKET_INSERT_BEFORE(a, b)
apr_file_t * fd
#define apr_bucket_read(e, str, len, block)
int apr_off_t * length
apr_brigade_flush void va_list va
@ APR_BLOCK_READ
Definition apr_buckets.h:58
@ APR_NONBLOCK_READ
Definition apr_buckets.h:59
const char apr_ssize_t int flags
Definition apr_encode.h:168
#define APR_HOOK_LINK(name)
Definition apr_hooks.h:139
#define APR_HOOK_STRUCT(members)
Definition apr_hooks.h:135
apr_redis_t * rc
Definition apr_redis.h:173
#define apr_strmatch(pattern, s, slen)
const char * uri
Definition apr_uri.h:159
apr_text_header * hdr
Definition apr_xml.h:77
#define HTTP_OK
Definition httpd.h:490
#define HTTP_BAD_REQUEST
Definition httpd.h:508
#define HTTP_REQUEST_TIME_OUT
Definition httpd.h:516
#define HTTP_CONTINUE
Definition httpd.h:487
#define HTTP_REQUEST_URI_TOO_LARGE
Definition httpd.h:522
#define AP_STATUS_IS_HEADER_ONLY(x)
Definition httpd.h:574
#define HTTP_VERSION_NOT_SUPPORTED
Definition httpd.h:540
#define HTTP_INTERNAL_SERVER_ERROR
Definition httpd.h:535
#define ap_is_HTTP_INFO(x)
Definition httpd.h:548
#define HTTP_EXPECTATION_FAILED
Definition httpd.h:525
#define HTTP_UNAUTHORIZED
Definition httpd.h:509
#define HTTP_NOT_IMPLEMENTED
Definition httpd.h:536
ap_filter_rec_t * ap_http_input_filter_handle
Definition http_core.c:38
#define M_OPTIONS
Definition httpd.h:597
#define M_CONNECT
Definition httpd.h:596
#define M_GET
Definition httpd.h:592
#define M_INVALID
Definition httpd.h:618
int ap_array_str_index(const apr_array_header_t *array, const char *s, int start)
Definition util.c:3428
const char const char int ap_is_chunked(apr_pool_t *p, const char *line)
Definition util.c:1786
const char * ap_scan_http_token(const char *ptr)
Definition util.c:1664
int ap_cstr_casecmp(const char *s1, const char *s2)
Definition util.c:3542
char * ap_getword(apr_pool_t *p, const char **line, char stop)
Definition util.c:723
char * ap_escape_logitem(apr_pool_t *p, const char *str)
Definition util.c:2183
#define ap_strchr_c(s, c)
Definition httpd.h:2353
#define AP_DEBUG_ASSERT(exp)
Definition httpd.h:2283
char * ap_pbase64decode(apr_pool_t *p, const char *bufcoded)
Definition util.c:2477
const char * ap_scan_vchar_obstext(const char *ptr)
Definition util.c:1674
char * ap_getword_nulls(apr_pool_t *p, const char **line, char stop)
Definition util.c:779
int ap_cstr_casecmpn(const char *s1, const char *s2, apr_size_t n)
Definition util.c:3559
#define PROXYREQ_PROXY
Definition httpd.h:1134
const char * ap_scan_http_field_content(const char *ptr)
Definition util.c:1654
int ap_parse_strict_length(apr_off_t *len, const char *str)
Definition util.c:2683
int ap_array_str_contains(const apr_array_header_t *array, const char *s)
Definition util.c:3446
@ AP_CONN_UNKNOWN
Definition httpd.h:1144
@ AP_CONN_CLOSE
Definition httpd.h:1145
apr_size_t size
apr_uint32_t val
Definition apr_atomic.h:66
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define apr_isspace(c)
Definition apr_lib.h:225
#define apr_isdigit(c)
Definition apr_lib.h:209
#define apr_tolower(c)
Definition apr_lib.h:231
const char * value
Definition apr_env.h:51
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
const char * key
void apr_size_t * nbytes
apr_seek_where_t apr_off_t * offset
void * data
void const char apr_status_t(* cleanup)(void *))
int type
apr_time_t mtime
#define APR_ASCII_BLANK
Definition apr_general.h:59
#define APR_ASCII_CR
Definition apr_general.h:61
#define APR_ASCII_LF
Definition apr_general.h:63
#define APR_ASCII_TAB
Definition apr_general.h:65
apr_vformatter_buff_t const char * fmt
Definition apr_lib.h:175
apr_vformatter_buff_t * c
Definition apr_lib.h:175
apr_interval_time_t t
int int int protocol
apr_pool_t * b
Definition apr_pools.h:529
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
const char char ** end
const char * s
Definition apr_strings.h:95
#define APR_ARRAY_PUSH(ary, type)
Definition apr_tables.h:150
#define APR_OVERLAP_TABLES_MERGE
Definition apr_tables.h:439
#define APR_ARRAY_IDX(ary, i, type)
Definition apr_tables.h:141
const char const char * password
const char * username
int int status
#define APR_RFC822_DATE_LEN
Definition apr_time.h:186
apr_int64_t apr_time_t
Definition apr_time.h:45
#define REQUEST_NO_BODY
Definition httpd.h:746
#define AP_REQ_DEFAULT_PATH_INFO
Definition httpd.h:765
Apache Configuration.
static const char * http_scheme(const request_rec *r)
Definition http_core.c:113
CORE HTTP Daemon.
#define AP_HTTP09_DISABLE
Definition http_core.h:742
#define ADD_DEFAULT_CHARSET_ON
Definition http_core.h:575
#define AP_HTTP_METHODS_REGISTERED
Definition http_core.h:752
#define AP_HTTP_CONFORMANCE_UNSAFE
Definition http_core.h:746
Apache Logging library.
Command line options.
HTTP protocol handling.
Apache Request library.
Virtual Host package.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
mod_core private header file
static int send_headers(request_rec *r, proxy_conn_rec *conn)
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
static int protocol_cmp(const apr_array_header_t *preferences, const char *proto1, const char *proto2)
Definition protocol.c:2377
static int table_do_fn_check_lengths(void *r_, const char *key, const char *value)
Definition protocol.c:1073
static void end_output_stream(request_rec *r, int status)
Definition protocol.c:1692
static apr_status_t buffer_output(request_rec *r, const char *str, apr_size_t len)
Definition protocol.c:2084
static int field_name_len(const char *field)
Definition protocol.c:647
static int r_flush(apr_vformatter_buff_t *buff)
Definition protocol.c:2152
static int send_header(void *data, const char *key, const char *val)
Definition protocol.c:2308
static const apr_strmatch_pattern * charset_pattern
Definition protocol.c:85
static ap_filter_t * insert_old_write_filter(request_rec *r)
Definition protocol.c:2057
static const apr_strmatch_pattern ** needcset_patterns
Definition protocol.c:84
static void strip_headers_request_body(request_rec *rnew)
Definition protocol.c:1634
#define LOG_NAME_MAX_LEN
Definition protocol.c:646
static int read_request_line(request_rec *r, apr_bucket_brigade *bb)
Definition protocol.c:655
static const char * needcset[]
Definition protocol.c:79
static void apply_server_config(request_rec *r)
Definition protocol.c:1413
int ap_rprintf(request_rec *r, const char *fmt,...)
Definition protocol.c:2205
Apache scoreboard library.
#define SERVER_BUSY_LOG
Definition scoreboard.h:62
int ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r)
Definition scoreboard.c:590
This structure is used for recording information about the registered filters. It associates a name w...
The representation of a filter chain.
apr_vformatter_buff_t vbuff
Definition protocol.c:2146
request_rec * r
Definition protocol.c:2147
apr_size_t length
apr_size_t size
Definition apr_mmap.h:82
char * fragment
Definition apr_uri.h:103
char * user
Definition apr_uri.h:91
char * scheme
Definition apr_uri.h:87
char * path
Definition apr_uri.h:99
char * password
Definition apr_uri.h:93
char * query
Definition apr_uri.h:101
char * hostname
Definition apr_uri.h:95
Structure to store things which are per connection.
Definition httpd.h:1152
apr_sockaddr_t * client_addr
Definition httpd.h:1166
apr_pool_t * pool
Definition httpd.h:1154
server_rec * base_server
Definition httpd.h:1156
ap_conn_keepalive_e keepalive
Definition httpd.h:1223
struct ap_filter_t * input_filters
Definition httpd.h:1195
struct ap_filter_t * output_filters
Definition httpd.h:1197
struct apr_bucket_alloc_t * bucket_alloc
Definition httpd.h:1201
char * client_ip
Definition httpd.h:1171
int keepalives
Definition httpd.h:1226
unsigned aborted
Definition httpd.h:1219
void * sbh
Definition httpd.h:1199
apr_bucket_brigade * tmpbb
Definition protocol.c:1854
Per-directory configuration.
Definition http_core.h:527
unsigned add_default_charset
Definition http_core.h:577
const char * add_default_charset_name
Definition http_core.h:578
Per-request configuration.
Definition http_core.h:394
apr_array_header_t * protocols
Definition http_core.h:737
unsigned int strict_host_check
Definition http_core.h:758
apr_bucket_brigade * bb
Definition protocol.c:2293
ap_filter_t * f
Definition protocol.c:2292
apr_bucket_brigade * bb
Definition protocol.c:2035
apr_bucket_brigade * tmpbb
Definition protocol.c:2036
A structure that represents the current request.
Definition httpd.h:845
char * user
Definition httpd.h:1005
int status
Definition httpd.h:891
int eos_sent
Definition httpd.h:1039
apr_off_t bytes_sent
Definition httpd.h:931
char * uri
Definition httpd.h:1016
apr_table_t * trailers_in
Definition httpd.h:1104
struct ap_filter_t * output_filters
Definition httpd.h:1070
char * useragent_ip
Definition httpd.h:1101
int assbackwards
Definition httpd.h:868
int read_body
Definition httpd.h:947
int header_only
Definition httpd.h:875
apr_time_t mtime
Definition httpd.h:933
struct ap_filter_t * proto_input_filters
Definition httpd.h:1079
apr_table_t * notes
Definition httpd.h:985
unsigned expecting_100
Definition httpd.h:951
const char * hostname
Definition httpd.h:883
int used_path_info
Definition httpd.h:1036
char * the_request
Definition httpd.h:866
int method_number
Definition httpd.h:898
apr_pool_t * pool
Definition httpd.h:847
apr_sockaddr_t * useragent_addr
Definition httpd.h:1100
apr_time_t request_time
Definition httpd.h:886
apr_uri_t parsed_uri
Definition httpd.h:1092
char * unparsed_uri
Definition httpd.h:1014
int proxyreq
Definition httpd.h:873
conn_rec * connection
Definition httpd.h:849
apr_bucket_brigade * kept_body
Definition httpd.h:953
ap_method_list_t * allowed_methods
Definition httpd.h:926
apr_table_t * err_headers_out
Definition httpd.h:981
struct ap_filter_t * proto_output_filters
Definition httpd.h:1076
int no_local_copy
Definition httpd.h:1084
int proto_num
Definition httpd.h:877
struct ap_filter_t * input_filters
Definition httpd.h:1072
struct ap_conf_vector_t * request_config
Definition httpd.h:1049
apr_table_t * headers_in
Definition httpd.h:976
char * protocol
Definition httpd.h:879
apr_off_t read_length
Definition httpd.h:961
request_rec * main
Definition httpd.h:860
apr_table_t * subprocess_env
Definition httpd.h:983
apr_off_t sent_bodyct
Definition httpd.h:929
server_rec * server
Definition httpd.h:851
struct ap_conf_vector_t * per_dir_config
Definition httpd.h:1047
apr_off_t clength
Definition httpd.h:940
const char * status_line
Definition httpd.h:889
const char * method
Definition httpd.h:900
char * args
Definition httpd.h:1026
apr_table_t * trailers_out
Definition httpd.h:1106
char * ap_auth_type
Definition httpd.h:1007
apr_table_t * headers_out
Definition httpd.h:978
A structure to store information for each virtual server.
Definition httpd.h:1322
apr_interval_time_t timeout
Definition httpd.h:1372
int limit_req_line
Definition httpd.h:1391
unsigned defn_line_number
Definition httpd.h:1348
const char * defn_name
Definition httpd.h:1346
int limit_req_fieldsize
Definition httpd.h:1393
int limit_req_fields
Definition httpd.h:1395
struct ap_conf_vector_t * lookup_defaults
Definition httpd.h:1343
struct ap_conf_vector_t * module_config
Definition httpd.h:1341
static apr_time_t now
Definition testtime.c:33
apr_status_t apr_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
Definition sockopt.c:75
apr_status_t apr_rfc822_date(char *date_str, apr_time_t t)
Definition timestr.c:42
charset conversion
Utilities for EBCDIC conversion.
#define str
Apache filter library.
@ AP_MODE_SPECULATIVE
Definition util_filter.h:53
@ AP_MODE_GETLINE
Definition util_filter.h:48
int ap_update_vhost_from_headers_ex(request_rec *r, int require_match)
Definition vhost.c:1173