]> granicus.if.org Git - apache/blob - include/http_protocol.h
Commit 4 on 6 to fix reentrance (incomplete Zlib header or validation bytes) in mod_d...
[apache] / include / http_protocol.h
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  * @file  http_protocol.h
19  * @brief HTTP protocol handling
20  *
21  * @defgroup APACHE_CORE_PROTO HTTP Protocol Handling
22  * @ingroup  APACHE_CORE
23  * @{
24  */
25
26 #ifndef APACHE_HTTP_PROTOCOL_H
27 #define APACHE_HTTP_PROTOCOL_H
28
29 #include "httpd.h"
30 #include "apr_portable.h"
31 #include "apr_mmap.h"
32 #include "apr_buckets.h"
33 #include "util_filter.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /**
40  * This hook allows modules to insert filters for the current error response
41  * @param r the current request
42  * @ingroup hooks
43  */
44 AP_DECLARE_HOOK(void,insert_error_filter,(request_rec *r))
45
46 /** This is an optimization.  We keep a record of the filter_rec that
47  * stores the old_write filter, so that we can avoid strcmp's later.
48  */
49 AP_DECLARE_DATA extern ap_filter_rec_t *ap_old_write_func;
50
51 /*
52  * Prototypes for routines which either talk directly back to the user,
53  * or control the ones that eventually do.
54  */
55
56 /**
57  * Read a request and fill in the fields.
58  * @param c The current connection
59  * @return The new request_rec
60  */
61 request_rec *ap_read_request(conn_rec *c);
62
63 /**
64  * Read the mime-encoded headers.
65  * @param r The current request
66  */
67 AP_DECLARE(void) ap_get_mime_headers(request_rec *r);
68
69 /**
70  * Optimized version of ap_get_mime_headers() that requires a
71  * temporary brigade to work with
72  * @param r The current request
73  * @param bb temp brigade
74  */
75 AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r,
76                                           apr_bucket_brigade *bb);
77
78 /* Finish up stuff after a request */
79
80 /**
81  * Called at completion of sending the response.  It sends the terminating
82  * protocol information.
83  * @param r The current request
84  */
85 AP_DECLARE(void) ap_finalize_request_protocol(request_rec *r);
86
87 /**
88  * Send error back to client.
89  * @param r The current request
90  * @param recursive_error last arg indicates error status in case we get
91  *      an error in the process of trying to deal with an ErrorDocument
92  *      to handle some other error.  In that case, we print the default
93  *      report for the first thing that went wrong, and more briefly report
94  *      on the problem with the ErrorDocument.
95  */
96 AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error);
97
98 /* Set last modified header line from the lastmod date of the associated file.
99  * Also, set content length.
100  *
101  * May return an error status, typically HTTP_NOT_MODIFIED (that when the
102  * permit_cache argument is set to one).
103  */
104
105 /**
106  * Set the content length for this request
107  * @param r The current request
108  * @param length The new content length
109  */
110 AP_DECLARE(void) ap_set_content_length(request_rec *r, apr_off_t length);
111
112 /**
113  * Set the keepalive status for this request
114  * @param r The current request
115  * @return 1 if keepalive can be set, 0 otherwise
116  */
117 AP_DECLARE(int) ap_set_keepalive(request_rec *r);
118
119 /**
120  * Return the latest rational time from a request/mtime pair.  Mtime is
121  * returned unless it's in the future, in which case we return the current time.
122  * @param r The current request
123  * @param mtime The last modified time
124  * @return the latest rational time.
125  */
126 AP_DECLARE(apr_time_t) ap_rationalize_mtime(request_rec *r, apr_time_t mtime);
127
128 /**
129  * Build the content-type that should be sent to the client from the
130  * content-type specified.  The following rules are followed:
131  *    - if type is NULL or "", return NULL (do not set content-type).
132  *    - if charset adding is disabled, stop processing and return type.
133  *    - then, if there are no parameters on type, add the default charset
134  *    - return type
135  * @param r The current request
136  * @param type The content type
137  * @return The content-type
138  */
139 AP_DECLARE(const char *) ap_make_content_type(request_rec *r,
140                                               const char *type);
141
142 /**
143  * Precompile metadata structures used by ap_make_content_type()
144  * @param pool The pool to use for allocations
145  */
146 AP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool);
147
148 /**
149  * Construct an entity tag from the resource information.  If it's a real
150  * file, build in some of the file characteristics.
151  * @param r The current request
152  * @param force_weak Force the entity tag to be weak - it could be modified
153  *                   again in as short an interval.
154  * @return The entity tag
155  */
156 AP_DECLARE(char *) ap_make_etag(request_rec *r, int force_weak);
157
158 /**
159  * Set the E-tag outgoing header
160  * @param r The current request
161  */
162 AP_DECLARE(void) ap_set_etag(request_rec *r);
163
164 /**
165  * Set the last modified time for the file being sent
166  * @param r The current request
167  */
168 AP_DECLARE(void) ap_set_last_modified(request_rec *r);
169
170 typedef enum {
171     AP_CONDITION_NONE,
172     AP_CONDITION_NOMATCH,
173     AP_CONDITION_WEAK,
174     AP_CONDITION_STRONG
175 } ap_condition_e;
176
177 /**
178  * Tests conditional request rules for the If-Match header.
179  * @param r The current request
180  * @param headers The response headers to check against
181  * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
182  *         if the header does not match, AP_CONDITION_STRONG for a strong
183  *         match. Weak matches are not permitted for the If-Match header.
184  */
185 AP_DECLARE(ap_condition_e) ap_condition_if_match(request_rec *r,
186         apr_table_t *headers);
187
188 /**
189  * Tests conditional request rules for the If-Unmodified-Since header.
190  * @param r The current request
191  * @param headers The response headers to check against
192  * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
193  *         if the header does not match, AP_CONDITION_WEAK if a weak match
194  *         was present and allowed by RFC2616, AP_CONDITION_STRONG for a
195  *         strong match.
196  */
197 AP_DECLARE(ap_condition_e) ap_condition_if_unmodified_since(request_rec *r,
198         apr_table_t *headers);
199
200 /**
201  * Tests conditional request rules for the If-None-Match header.
202  * @param r The current request
203  * @param headers The response headers to check against
204  * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
205  *         if the header does not match, AP_CONDITION_WEAK if a weak match
206  *         was present and allowed by RFC2616, AP_CONDITION_STRONG for a
207  *         strong match.
208  */
209 AP_DECLARE(ap_condition_e) ap_condition_if_none_match(request_rec *r,
210         apr_table_t *headers);
211
212 /**
213  * Tests conditional request rules for the If-Modified-Since header.
214  * @param r The current request
215  * @param headers The response headers to check against
216  * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
217  *         if the header does not match, AP_CONDITION_WEAK if a weak match
218  *         was present and allowed by RFC2616, AP_CONDITION_STRONG for a
219  *         strong match.
220  */
221 AP_DECLARE(ap_condition_e) ap_condition_if_modified_since(request_rec *r,
222         apr_table_t *headers);
223
224 /**
225  * Tests conditional request rules for the If-Range header.
226  * @param r The current request
227  * @param headers The response headers to check against
228  * @return AP_CONDITION_NONE if either the If-Range or Range header is
229  *         missing, AP_CONDITION_NOMATCH if the header does not match,
230  *         AP_CONDITION_STRONG for a strong match. Weak matches are not
231  *         permitted for the If-Range header.
232  */
233 AP_DECLARE(ap_condition_e) ap_condition_if_range(request_rec *r,
234         apr_table_t *headers);
235
236 /**
237  * Implements condition GET rules for HTTP/1.1 specification.  This function
238  * inspects the client headers and determines if the response fulfills
239  * the requirements specified.
240  * @param r The current request
241  * @return OK if the response fulfills the condition GET rules, some
242  *         other status code otherwise
243  */
244 AP_DECLARE(int) ap_meets_conditions(request_rec *r);
245
246 /* Other ways to send stuff at the client.  All of these keep track
247  * of bytes_sent automatically.  This indirection is intended to make
248  * it a little more painless to slide things like HTTP-NG packetization
249  * underneath the main body of the code later.  In the meantime, it lets
250  * us centralize a bit of accounting (bytes_sent).
251  *
252  * These also return the number of bytes written by the call.
253  * They should only be called with a timeout registered, for obvious reaasons.
254  * (Ditto the send_header stuff).
255  */
256
257 /**
258  * Send an entire file to the client, using sendfile if supported by the
259  * current platform
260  * @param fd The file to send.
261  * @param r The current request
262  * @param offset Offset into the file to start sending.
263  * @param length Amount of data to send
264  * @param nbytes Amount of data actually sent
265  */
266 AP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset,
267                                    apr_size_t length, apr_size_t *nbytes);
268
269 #if APR_HAS_MMAP
270 /**
271  * Send an MMAP'ed file to the client
272  * @param mm The MMAP'ed file to send
273  * @param r The current request
274  * @param offset The offset into the MMAP to start sending
275  * @param length The amount of data to send
276  * @return The number of bytes sent
277  */
278 AP_DECLARE(apr_size_t) ap_send_mmap(apr_mmap_t *mm,
279                                     request_rec *r,
280                                     apr_size_t offset,
281                                     apr_size_t length);
282 #endif
283
284
285 /**
286  * Register a new request method, and return the offset that will be
287  * associated with that method.
288  *
289  * @param p        The pool to create registered method numbers from.
290  * @param methname The name of the new method to register.
291  * @return         An int value representing an offset into a bitmask.
292  */
293 AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname);
294
295 /**
296  * Initialize the method_registry and allocate memory for it.
297  *
298  * @param p Pool to allocate memory for the registry from.
299  */
300 AP_DECLARE(void) ap_method_registry_init(apr_pool_t *p);
301
302 /**
303  * This is a convenience macro to ease with checking a mask
304  * against a method name.
305  */
306 #define AP_METHOD_CHECK_ALLOWED(mask, methname) \
307     ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname))))
308
309 /**
310  * Create a new method list with the specified number of preallocated
311  * slots for extension methods.
312  *
313  * @param   p       Pointer to a pool in which the structure should be
314  *                  allocated.
315  * @param   nelts   Number of preallocated extension slots
316  * @return  Pointer to the newly created structure.
317  */
318 AP_DECLARE(ap_method_list_t *) ap_make_method_list(apr_pool_t *p, int nelts);
319
320
321 /**
322  * Copy a method list
323  *
324  * @param   dest List to copy to
325  * @param   src  List to copy from
326  */
327 AP_DECLARE(void) ap_copy_method_list(ap_method_list_t *dest,
328                                      ap_method_list_t *src);
329
330 /**
331  * Search for an HTTP method name in an ap_method_list_t structure, and
332  * return true if found.
333  *
334  * @param   method  String containing the name of the method to check.
335  * @param   l       Pointer to a method list, such as r->allowed_methods.
336  * @return  1 if method is in the list, otherwise 0
337  */
338 AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *method);
339
340 /**
341  * Add an HTTP method name to an ap_method_list_t structure if it isn't
342  * already listed.
343  *
344  * @param   method  String containing the name of the method to check.
345  * @param   l       Pointer to a method list, such as r->allowed_methods.
346  * @return  None.
347  */
348 AP_DECLARE(void) ap_method_list_add(ap_method_list_t *l, const char *method);
349
350 /**
351  * Remove an HTTP method name from an ap_method_list_t structure.
352  *
353  * @param   l       Pointer to a method list, such as r->allowed_methods.
354  * @param   method  String containing the name of the method to remove.
355  * @return  None.
356  */
357 AP_DECLARE(void) ap_method_list_remove(ap_method_list_t *l,
358                                        const char *method);
359
360 /**
361  * Reset a method list to be completely empty.
362  *
363  * @param   l       Pointer to a method list, such as r->allowed_methods.
364  * @return  None.
365  */
366 AP_DECLARE(void) ap_clear_method_list(ap_method_list_t *l);
367
368 /**
369  * Set the content type for this request (r->content_type).
370  * @param r The current request
371  * @param ct The new content type
372  * @warning This function must be called to set r->content_type in order
373  * for the AddOutputFilterByType directive to work correctly.
374  */
375 AP_DECLARE(void) ap_set_content_type(request_rec *r, const char *ct);
376
377 /**
378  * Set the Accept-Ranges header for this response
379  * @param r The current request
380  */
381 AP_DECLARE(void) ap_set_accept_ranges(request_rec *r);
382
383
384 /* Hmmm... could macrofy these for now, and maybe forever, though the
385  * definitions of the macros would get a whole lot hairier.
386  */
387
388 /**
389  * Output one character for this request
390  * @param c the character to output
391  * @param r the current request
392  * @return The number of bytes sent
393  */
394 AP_DECLARE(int) ap_rputc(int c, request_rec *r);
395
396 /**
397  * Write a buffer for the current request
398  * @param buf The buffer to write
399  * @param nbyte The number of bytes to send from the buffer
400  * @param r The current request
401  * @return The number of bytes sent
402  */
403 AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r);
404
405 /**
406  * Output a string for the current request
407  * @param str The string to output
408  * @param r The current request
409  * @return The number of bytes sent
410  * @note ap_rputs may be implemented as macro or inline function
411  */
412 static APR_INLINE int ap_rputs(const char *str, request_rec *r)
413 {
414     return ap_rwrite(str, (int)strlen(str), r);
415 }
416
417 /**
418  * Write an unspecified number of strings to the request
419  * @param r The current request
420  * @param ... The strings to write
421  * @return The number of bytes sent
422  */
423 AP_DECLARE_NONSTD(int) ap_rvputs(request_rec *r,...)
424                        AP_FN_ATTR_SENTINEL;
425
426 /**
427  * Output data to the client in a printf format
428  * @param r The current request
429  * @param fmt The format string
430  * @param vlist The arguments to use to fill out the format string
431  * @return The number of bytes sent
432  */
433 AP_DECLARE(int) ap_vrprintf(request_rec *r, const char *fmt, va_list vlist);
434
435 /**
436  * Output data to the client in a printf format
437  * @param r The current request
438  * @param fmt The format string
439  * @param ... The arguments to use to fill out the format string
440  * @return The number of bytes sent
441  */
442 AP_DECLARE_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt,...)
443                                 __attribute__((format(printf,2,3)));
444
445 /**
446  * Flush all of the data for the current request to the client
447  * @param r The current request
448  * @return 0 on success, -1 if an error occurred
449  */
450 AP_DECLARE(int) ap_rflush(request_rec *r);
451
452 /**
453  * Index used in custom_responses array for a specific error code
454  * (only use outside protocol.c is in getting them configured).
455  * @param status HTTP status code
456  * @return The index of the response
457  */
458 AP_DECLARE(int) ap_index_of_response(int status);
459
460 /**
461  * Return the Status-Line for a given status code (excluding the
462  * HTTP-Version field). If an invalid or unknown status code is
463  * passed, "500 Internal Server Error" will be returned.
464  * @param status The HTTP status code
465  * @return The Status-Line
466  */
467 AP_DECLARE(const char *) ap_get_status_line(int status);
468
469 /* Reading a block of data from the client connection (e.g., POST arg) */
470
471 /**
472  * Setup the client to allow Apache to read the request body.
473  * @param r The current request
474  * @param read_policy How the server should interpret a chunked
475  *                    transfer-encoding.  One of: <pre>
476  *    REQUEST_NO_BODY          Send 413 error if message has any body
477  *    REQUEST_CHUNKED_ERROR    Send 411 error if body without Content-Length
478  *    REQUEST_CHUNKED_DECHUNK  If chunked, remove the chunks for me.
479  * </pre>
480  * @return either OK or an error code
481  */
482 AP_DECLARE(int) ap_setup_client_block(request_rec *r, int read_policy);
483
484 /**
485  * Determine if the client has sent any data.  This also sends a
486  * 100 Continue response to HTTP/1.1 clients, so modules should not be called
487  * until the module is ready to read content.
488  * @warning Never call this function more than once.
489  * @param r The current request
490  * @return 0 if there is no message to read, 1 otherwise
491  */
492 AP_DECLARE(int) ap_should_client_block(request_rec *r);
493
494 /**
495  * Call this in a loop.  It will put data into a buffer and return the length
496  * of the input block
497  * @param r The current request
498  * @param buffer The buffer in which to store the data
499  * @param bufsiz The size of the buffer
500  * @return Number of bytes inserted into the buffer.  When done reading, 0
501  *         if EOF, or -1 if there was an error
502  */
503 AP_DECLARE(long) ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz);
504
505 /*
506  * Map specific APR codes returned by the filter stack to HTTP error
507  * codes, or the default status code provided. Use it as follows:
508  *
509  * return ap_map_http_request_error(rv, HTTP_BAD_REQUEST);
510  *
511  * If the filter has already handled the error, AP_FILTER_ERROR will
512  * be returned, which is cleanly passed through.
513  *
514  * These mappings imply that the filter stack is reading from the
515  * downstream client, the proxy will map these codes differently.
516  * @param rv APR status code
517  * @param status Default HTTP code should the APR code not be recognised
518  * @return Mapped HTTP status code
519  */
520 AP_DECLARE(int) ap_map_http_request_error(apr_status_t rv, int status);
521
522 /**
523  * In HTTP/1.1, any method can have a body.  However, most GET handlers
524  * wouldn't know what to do with a request body if they received one.
525  * This helper routine tests for and reads any message body in the request,
526  * simply discarding whatever it receives.  We need to do this because
527  * failing to read the request body would cause it to be interpreted
528  * as the next request on a persistent connection.
529  * @param r The current request
530  * @return error status if request is malformed, OK otherwise
531  */
532 AP_DECLARE(int) ap_discard_request_body(request_rec *r);
533
534 /**
535  * Setup the output headers so that the client knows how to authenticate
536  * itself the next time, if an authentication request failed.
537  * @param r The current request
538  */
539 AP_DECLARE(void) ap_note_auth_failure(request_rec *r);
540
541 /**
542  * @deprecated @see ap_note_auth_failure
543  */
544 AP_DECLARE(void) ap_note_basic_auth_failure(request_rec *r);
545
546 /**
547  * @deprecated @see ap_note_auth_failure
548  */
549 AP_DECLARE(void) ap_note_digest_auth_failure(request_rec *r);
550
551 /**
552  * This hook allows modules to add support for a specific auth type to
553  * ap_note_auth_failure
554  * @param r the current request
555  * @param auth_type the configured auth_type
556  * @return OK, DECLINED
557  */
558 AP_DECLARE_HOOK(int, note_auth_failure, (request_rec *r, const char *auth_type))
559
560 /**
561  * Get the password from the request headers
562  * @param r The current request
563  * @param pw The password as set in the headers
564  * @return 0 (OK) if it set the 'pw' argument (and assured
565  *         a correct value in r->user); otherwise it returns
566  *         an error code, either HTTP_INTERNAL_SERVER_ERROR if things are
567  *         really confused, HTTP_UNAUTHORIZED if no authentication at all
568  *         seemed to be in use, or DECLINED if there was authentication but
569  *         it wasn't Basic (in which case, the caller should presumably
570  *         decline as well).
571  */
572 AP_DECLARE(int) ap_get_basic_auth_pw(request_rec *r, const char **pw);
573
574 /**
575  * parse_uri: break apart the uri
576  * @warning Side Effects:
577  *    @li sets r->args to rest after '?' (or NULL if no '?')
578  *    @li sets r->uri to request uri (without r->args part)
579  *    @li sets r->hostname (if not set already) from request (scheme://host:port)
580  * @param r The current request
581  * @param uri The uri to break apart
582  */
583 AP_CORE_DECLARE(void) ap_parse_uri(request_rec *r, const char *uri);
584
585 /**
586  * Get the next line of input for the request
587  * @param s The buffer into which to read the line
588  * @param n The size of the buffer
589  * @param r The request
590  * @param fold Whether to merge continuation lines
591  * @return The length of the line, if successful
592  *         n, if the line is too big to fit in the buffer
593  *         -1 for miscellaneous errors
594  */
595 AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int fold);
596
597 /**
598  * Get the next line of input for the request
599  *
600  * Note: on ASCII boxes, ap_rgetline is a macro which simply calls
601  *       ap_rgetline_core to get the line of input.
602  *
603  *       on EBCDIC boxes, ap_rgetline is a wrapper function which
604  *       translates ASCII protocol lines to the local EBCDIC code page
605  *       after getting the line of input.
606  *
607  * @param s Pointer to the pointer to the buffer into which the line
608  *          should be read; if *s==NULL, a buffer of the necessary size
609  *          to hold the data will be allocated from the request pool
610  * @param n The size of the buffer
611  * @param read The length of the line.
612  * @param r The request
613  * @param fold Whether to merge continuation lines
614  * @param bb Working brigade to use when reading buckets
615  * @return APR_SUCCESS, if successful
616  *         APR_ENOSPC, if the line is too big to fit in the buffer
617  *         Other errors where appropriate
618  */
619 #if APR_CHARSET_EBCDIC
620 AP_DECLARE(apr_status_t) ap_rgetline(char **s, apr_size_t n,
621                                      apr_size_t *read,
622                                      request_rec *r, int fold,
623                                      apr_bucket_brigade *bb);
624 #else /* ASCII box */
625 #define ap_rgetline(s, n, read, r, fold, bb) \
626         ap_rgetline_core((s), (n), (read), (r), (fold), (bb))
627 #endif
628
629 /** @see ap_rgetline */
630 AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
631                                           apr_size_t *read,
632                                           request_rec *r, int fold,
633                                           apr_bucket_brigade *bb);
634
635 /**
636  * Get the method number associated with the given string, assumed to
637  * contain an HTTP method.  Returns M_INVALID if not recognized.
638  * @param method A string containing a valid HTTP method
639  * @return The method number
640  */
641 AP_DECLARE(int) ap_method_number_of(const char *method);
642
643 /**
644  * Get the method name associated with the given internal method
645  * number.  Returns NULL if not recognized.
646  * @param p A pool to use for temporary allocations.
647  * @param methnum An integer value corresponding to an internal method number
648  * @return The name corresponding to the method number
649  */
650 AP_DECLARE(const char *) ap_method_name_of(apr_pool_t *p, int methnum);
651
652
653 /* Hooks */
654 /*
655  * pre_read_request --- run right before read_request_line(),
656  *                  and not run during any subrequests.
657  */
658 /**
659  * This hook allows modules to affect the request or connection immediately before
660  * the request has been read, and before any other phases have been processes.
661  * @param r The current request of the soon-to-be-read request
662  * @param c The connection
663  * @return None/void
664  */
665 AP_DECLARE_HOOK(void,pre_read_request,(request_rec *r, conn_rec *c))
666
667 /*
668  * post_read_request --- run right after read_request or internal_redirect,
669  *                  and not run during any subrequests.
670  */
671 /**
672  * This hook allows modules to affect the request immediately after the request
673  * has been read, and before any other phases have been processes.  This allows
674  * modules to make decisions based upon the input header fields
675  * @param r The current request
676  * @return OK or DECLINED
677  */
678 AP_DECLARE_HOOK(int,post_read_request,(request_rec *r))
679
680 /**
681  * This hook allows modules to perform any module-specific logging activities
682  * over and above the normal server things.
683  * @param r The current request
684  * @return OK, DECLINED, or HTTP_...
685  */
686 AP_DECLARE_HOOK(int,log_transaction,(request_rec *r))
687
688 /**
689  * This hook allows modules to retrieve the http scheme for a request.  This
690  * allows Apache modules to easily extend the schemes that Apache understands
691  * @param r The current request
692  * @return The http scheme from the request
693  */
694 AP_DECLARE_HOOK(const char *,http_scheme,(const request_rec *r))
695
696 /**
697  * Return the default port from the current request
698  * @param r The current request
699  * @return The current port
700  */
701 AP_DECLARE_HOOK(apr_port_t,default_port,(const request_rec *r))
702
703 /** @see ap_bucket_type_error */
704 typedef struct ap_bucket_error ap_bucket_error;
705
706 /**
707  * @struct ap_bucket_error
708  * @brief  A bucket referring to an HTTP error
709  *
710  * This bucket can be passed down the filter stack to indicate that an
711  * HTTP error occurred while running a filter.  In order for this bucket
712  * to be used successfully, it MUST be sent as the first bucket in the
713  * first brigade to be sent from a given filter.
714  */
715 struct ap_bucket_error {
716     /** Number of buckets using this memory */
717     apr_bucket_refcount refcount;
718     /** The error code */
719     int status;
720     /** The error string */
721     const char    *data;
722 };
723
724 /** @see ap_bucket_type_error */
725 AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_error;
726
727 /**
728  * Determine if a bucket is an error bucket
729  * @param e The bucket to inspect
730  * @return true or false
731  */
732 #define AP_BUCKET_IS_ERROR(e)         (e->type == &ap_bucket_type_error)
733
734 /**
735  * Make the bucket passed in an error bucket
736  * @param b The bucket to make into an error bucket
737  * @param error The HTTP error code to put in the bucket.
738  * @param buf An optional error string to put in the bucket.
739  * @param p A pool to allocate out of.
740  * @return The new bucket, or NULL if allocation failed
741  */
742 AP_DECLARE(apr_bucket *) ap_bucket_error_make(apr_bucket *b, int error,
743                 const char *buf, apr_pool_t *p);
744
745 /**
746  * Create a bucket referring to an HTTP error.
747  * @param error The HTTP error code to put in the bucket.
748  * @param buf An optional error string to put in the bucket.
749  * @param p A pool to allocate the error string out of.
750  * @param list The bucket allocator from which to allocate the bucket
751  * @return The new bucket, or NULL if allocation failed
752  */
753 AP_DECLARE(apr_bucket *) ap_bucket_error_create(int error, const char *buf,
754                                                 apr_pool_t *p,
755                                                 apr_bucket_alloc_t *list);
756
757 AP_DECLARE_NONSTD(apr_status_t) ap_byterange_filter(ap_filter_t *f, apr_bucket_brigade *b);
758 AP_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, apr_bucket_brigade *b);
759 AP_DECLARE_NONSTD(apr_status_t) ap_content_length_filter(ap_filter_t *,
760                                                               apr_bucket_brigade *);
761 AP_DECLARE_NONSTD(apr_status_t) ap_old_write_filter(ap_filter_t *f, apr_bucket_brigade *b);
762
763 /**
764  * Sett up the protocol fields for subsidiary requests
765  * @param rnew New Sub Request
766  * @param r current request
767  */
768 AP_DECLARE(void) ap_set_sub_req_protocol(request_rec *rnew, const request_rec *r);
769
770 /**
771  * A wrapup function to keep the internal accounting straight.
772  * Indicates that there is no more content coming.
773  * @param sub_r Subrequest that is now compete
774  */
775 AP_DECLARE(void) ap_finalize_sub_req_protocol(request_rec *sub_r);
776
777 /**
778  * Send an interim (HTTP 1xx) response immediately.
779  * @param r The request
780  * @param send_headers Whether to send&clear headers in r->headers_out
781  */
782 AP_DECLARE(void) ap_send_interim_response(request_rec *r, int send_headers);
783
784 #ifdef __cplusplus
785 }
786 #endif
787
788 #endif  /* !APACHE_HTTP_PROTOCOL_H */
789 /** @} */