Coverage Report

Created: 2025-07-11 06:40

/src/httpd/include/http_protocol.h
Line
Count
Source (jump to first uncovered line)
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 an empty request and set reasonable defaults.
58
 * @param c The current connection
59
 * @return The new request_rec
60
 */
61
AP_DECLARE(request_rec *) ap_create_request(conn_rec *c);
62
63
/**
64
 * Read a request and fill in the fields.
65
 * @param c The current connection
66
 * @return The new request_rec
67
 */
68
AP_DECLARE(request_rec *) ap_read_request(conn_rec *c);
69
70
/**
71
 * Assign the method, uri and protocol (in HTTP/1.x the
72
 * items from the first line) to the request.
73
 * @param r The current request
74
 * @param method the HTTP method
75
 * @param uri the request uri
76
 * @param protocol the request protocol
77
 * @return 1 on success, 0 on failure
78
 */
79
AP_DECLARE(int) ap_assign_request_line(request_rec *r,
80
                                       const char *method, const char *uri,
81
                                       const char *protocol);
82
83
/**
84
 * Parse a HTTP/1.x request line, validate and return the components
85
 * @param r The current request
86
 * @param line the line to parse
87
 * @param pmethod the parsed method on success
88
 * @param puri the parsed uri on success
89
 * @param pprotocol the parsed protocol on success
90
 * @return 1 on success, 0 on failure
91
 */
92
AP_DECLARE(int) ap_h1_tokenize_request_line(
93
        request_rec *r, const char *line,
94
        const char **pmethod, const char **puri, const char **pprotocol);
95
96
/**
97
 * Parse and validate the request line.
98
 * @param r The current request
99
 * @return 1 on success, 0 on failure
100
 */
101
AP_DECLARE(int) ap_parse_request_line(request_rec *r);
102
103
/**
104
 * Validate the request header and select vhost.
105
 * @param r The current request
106
 * @return 1 on success, 0 on failure
107
 */
108
AP_DECLARE(int) ap_check_request_header(request_rec *r);
109
110
/**
111
 * Read the mime-encoded headers.
112
 * @param r The current request
113
 */
114
AP_DECLARE(void) ap_get_mime_headers(request_rec *r);
115
116
/**
117
 * Optimized version of ap_get_mime_headers() that requires a
118
 * temporary brigade to work with
119
 * @param r The current request
120
 * @param bb temp brigade
121
 */
122
AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r,
123
                                          apr_bucket_brigade *bb);
124
125
/**
126
 * Run post_read_request hook and validate.
127
 * @param r The current request
128
 * @return OK or HTTP_...
129
 */
130
AP_DECLARE(int) ap_post_read_request(request_rec *r);
131
132
/* Finish up stuff after a request */
133
134
/**
135
 * Called at completion of sending the response.  It sends the terminating
136
 * protocol information.
137
 * @param r The current request
138
 */
139
AP_DECLARE(void) ap_finalize_request_protocol(request_rec *r);
140
141
/**
142
 * Send error back to client.
143
 * @param r The current request
144
 * @param recursive_error last arg indicates error status in case we get
145
 *      an error in the process of trying to deal with an ErrorDocument
146
 *      to handle some other error.  In that case, we print the default
147
 *      report for the first thing that went wrong, and more briefly report
148
 *      on the problem with the ErrorDocument.
149
 */
150
AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error);
151
152
/* Set last modified header line from the lastmod date of the associated file.
153
 * Also, set content length.
154
 *
155
 * May return an error status, typically HTTP_NOT_MODIFIED (that when the
156
 * permit_cache argument is set to one).
157
 */
158
159
/**
160
 * Set the content length for this request
161
 * @param r The current request
162
 * @param length The new content length
163
 */
164
AP_DECLARE(void) ap_set_content_length(request_rec *r, apr_off_t length);
165
166
/**
167
 * Set the keepalive status for this request
168
 * @param r The current request
169
 * @return 1 if keepalive can be set, 0 otherwise
170
 */
171
AP_DECLARE(int) ap_set_keepalive(request_rec *r);
172
173
/**
174
 * Return the latest rational time from a request/mtime pair.  Mtime is
175
 * returned unless it's in the future, in which case we return the current time.
176
 * @param r The current request
177
 * @param mtime The last modified time
178
 * @return the latest rational time.
179
 */
180
AP_DECLARE(apr_time_t) ap_rationalize_mtime(request_rec *r, apr_time_t mtime);
181
182
/**
183
 * Build the content-type that should be sent to the client from the
184
 * content-type specified.  The following rules are followed:
185
 *    - if type is NULL or "", return NULL (do not set content-type).
186
 *    - if charset adding is disabled, stop processing and return type.
187
 *    - then, if there are no parameters on type, add the default charset
188
 *    - return type
189
 * @param r The current request
190
 * @param type The content type
191
 * @return The content-type
192
 */
193
AP_DECLARE(const char *) ap_make_content_type(request_rec *r,
194
                                              const char *type);
195
196
/**
197
 * Precompile metadata structures used by ap_make_content_type()
198
 * @param pool The pool to use for allocations
199
 */
200
AP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool);
201
202
/** A structure with the ingredients for a file based etag */
203
typedef struct etag_rec etag_rec;
204
205
/**
206
 * @brief A structure with the ingredients for a file based etag
207
 */
208
struct etag_rec {
209
    /** Optional vary list validator */
210
    const char *vlist_validator;
211
    /** Time when the request started */
212
    apr_time_t request_time;
213
    /** finfo.protection (st_mode) set to zero if no such file */
214
    apr_finfo_t *finfo;
215
    /** File pathname used when generating a digest */
216
    const char *pathname;
217
    /** File descriptor used when generating a digest */
218
    apr_file_t *fd;
219
    /** Force a non-digest etag to be weak */
220
    int force_weak;
221
};
222
223
/**
224
 * Construct an entity tag from the resource information.  If it's a real
225
 * file, build in some of the file characteristics.
226
 * @param r The current request
227
 * @param force_weak Force the entity tag to be weak - it could be modified
228
 *                   again in as short an interval.
229
 * @return The entity tag
230
 */
231
AP_DECLARE(char *) ap_make_etag(request_rec *r, int force_weak);
232
233
/**
234
 * Construct an entity tag from information provided in the etag_rec
235
 * structure.
236
 * @param r The current request
237
 * @param er The etag record, containing ingredients for the etag.
238
 */
239
AP_DECLARE(char *) ap_make_etag_ex(request_rec *r, etag_rec *er);
240
241
/**
242
 * Set the E-tag outgoing header
243
 * @param r The current request
244
 */
245
AP_DECLARE(void) ap_set_etag(request_rec *r);
246
247
/**
248
 * Set the E-tag outgoing header, with the option of forcing a strong ETag.
249
 * @param r The current request
250
 * @param fd The file descriptor
251
 */
252
AP_DECLARE(void) ap_set_etag_fd(request_rec *r, apr_file_t *fd);
253
254
/**
255
 * Set the last modified time for the file being sent
256
 * @param r The current request
257
 */
258
AP_DECLARE(void) ap_set_last_modified(request_rec *r);
259
260
typedef enum {
261
    AP_CONDITION_NONE,
262
    AP_CONDITION_NOMATCH,
263
    AP_CONDITION_WEAK,
264
    AP_CONDITION_STRONG
265
} ap_condition_e;
266
267
/**
268
 * Tests conditional request rules for the If-Match header.
269
 * @param r The current request
270
 * @param headers The response headers to check against
271
 * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
272
 *         if the header does not match, AP_CONDITION_STRONG for a strong
273
 *         match. Weak matches are not permitted for the If-Match header.
274
 */
275
AP_DECLARE(ap_condition_e) ap_condition_if_match(request_rec *r,
276
        apr_table_t *headers);
277
278
/**
279
 * Tests conditional request rules for the If-Unmodified-Since header.
280
 * @param r The current request
281
 * @param headers The response headers to check against
282
 * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
283
 *         if the header does not match, AP_CONDITION_WEAK if a weak match
284
 *         was present and allowed by RFC2616, AP_CONDITION_STRONG for a
285
 *         strong match.
286
 */
287
AP_DECLARE(ap_condition_e) ap_condition_if_unmodified_since(request_rec *r,
288
        apr_table_t *headers);
289
290
/**
291
 * Tests conditional request rules for the If-None-Match header.
292
 * @param r The current request
293
 * @param headers The response headers to check against
294
 * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
295
 *         if the header does not match, AP_CONDITION_WEAK if a weak match
296
 *         was present and allowed by RFC2616, AP_CONDITION_STRONG for a
297
 *         strong match.
298
 */
299
AP_DECLARE(ap_condition_e) ap_condition_if_none_match(request_rec *r,
300
        apr_table_t *headers);
301
302
/**
303
 * Tests conditional request rules for the If-Modified-Since header.
304
 * @param r The current request
305
 * @param headers The response headers to check against
306
 * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH
307
 *         if the header does not match, AP_CONDITION_WEAK if a weak match
308
 *         was present and allowed by RFC2616, AP_CONDITION_STRONG for a
309
 *         strong match.
310
 */
311
AP_DECLARE(ap_condition_e) ap_condition_if_modified_since(request_rec *r,
312
        apr_table_t *headers);
313
314
/**
315
 * Tests conditional request rules for the If-Range header.
316
 * @param r The current request
317
 * @param headers The response headers to check against
318
 * @return AP_CONDITION_NONE if either the If-Range or Range header is
319
 *         missing, AP_CONDITION_NOMATCH if the header does not match,
320
 *         AP_CONDITION_STRONG for a strong match. Weak matches are not
321
 *         permitted for the If-Range header.
322
 */
323
AP_DECLARE(ap_condition_e) ap_condition_if_range(request_rec *r,
324
        apr_table_t *headers);
325
326
/**
327
 * Implements condition GET rules for HTTP/1.1 specification.  This function
328
 * inspects the client headers and determines if the response fulfills
329
 * the requirements specified.
330
 * @param r The current request
331
 * @return OK if the response fulfills the condition GET rules, some
332
 *         other status code otherwise
333
 */
334
AP_DECLARE(int) ap_meets_conditions(request_rec *r);
335
336
/* Other ways to send stuff at the client.  All of these keep track
337
 * of bytes_sent automatically.  This indirection is intended to make
338
 * it a little more painless to slide things like HTTP-NG packetization
339
 * underneath the main body of the code later.  In the meantime, it lets
340
 * us centralize a bit of accounting (bytes_sent).
341
 *
342
 * These also return the number of bytes written by the call.
343
 * They should only be called with a timeout registered, for obvious reaasons.
344
 * (Ditto the send_header stuff).
345
 */
346
347
/**
348
 * Send an entire file to the client, using sendfile if supported by the
349
 * current platform
350
 * @param fd The file to send.
351
 * @param r The current request
352
 * @param offset Offset into the file to start sending.
353
 * @param length Amount of data to send
354
 * @param nbytes Amount of data actually sent
355
 */
356
AP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset,
357
                                   apr_size_t length, apr_size_t *nbytes);
358
359
#if APR_HAS_MMAP
360
/**
361
 * Send an MMAP'ed file to the client
362
 * @param mm The MMAP'ed file to send
363
 * @param r The current request
364
 * @param offset The offset into the MMAP to start sending
365
 * @param length The amount of data to send
366
 * @return The number of bytes sent
367
 */
368
AP_DECLARE(apr_size_t) ap_send_mmap(apr_mmap_t *mm,
369
                                    request_rec *r,
370
                                    apr_size_t offset,
371
                                    apr_size_t length);
372
#endif
373
374
375
/**
376
 * Register a new request method, and return the offset that will be
377
 * associated with that method.
378
 *
379
 * @param p        The pool to create registered method numbers from.
380
 * @param methname The name of the new method to register.
381
 * @return         An int value representing an offset into a bitmask.
382
 */
383
AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname);
384
385
/**
386
 * Initialize the method_registry and allocate memory for it.
387
 *
388
 * @param p Pool to allocate memory for the registry from.
389
 */
390
AP_DECLARE(void) ap_method_registry_init(apr_pool_t *p);
391
392
/**
393
 * This is a convenience macro to ease with checking a mask
394
 * against a method name.
395
 */
396
#define AP_METHOD_CHECK_ALLOWED(mask, methname) \
397
    ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname))))
398
399
/**
400
 * Create a new method list with the specified number of preallocated
401
 * slots for extension methods.
402
 *
403
 * @param   p       Pointer to a pool in which the structure should be
404
 *                  allocated.
405
 * @param   nelts   Number of preallocated extension slots
406
 * @return  Pointer to the newly created structure.
407
 */
408
AP_DECLARE(ap_method_list_t *) ap_make_method_list(apr_pool_t *p, int nelts);
409
410
411
/**
412
 * Copy a method list
413
 *
414
 * @param   dest List to copy to
415
 * @param   src  List to copy from
416
 */
417
AP_DECLARE(void) ap_copy_method_list(ap_method_list_t *dest,
418
                                     ap_method_list_t *src);
419
420
/**
421
 * Search for an HTTP method name in an ap_method_list_t structure, and
422
 * return true if found.
423
 *
424
 * @param   method  String containing the name of the method to check.
425
 * @param   l       Pointer to a method list, such as r->allowed_methods.
426
 * @return  1 if method is in the list, otherwise 0
427
 */
428
AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *method);
429
430
/**
431
 * Add an HTTP method name to an ap_method_list_t structure if it isn't
432
 * already listed.
433
 *
434
 * @param   method  String containing the name of the method to check.
435
 * @param   l       Pointer to a method list, such as r->allowed_methods.
436
 * @return  None.
437
 */
438
AP_DECLARE(void) ap_method_list_add(ap_method_list_t *l, const char *method);
439
440
/**
441
 * Remove an HTTP method name from an ap_method_list_t structure.
442
 *
443
 * @param   l       Pointer to a method list, such as r->allowed_methods.
444
 * @param   method  String containing the name of the method to remove.
445
 * @return  None.
446
 */
447
AP_DECLARE(void) ap_method_list_remove(ap_method_list_t *l,
448
                                       const char *method);
449
450
/**
451
 * Reset a method list to be completely empty.
452
 *
453
 * @param   l       Pointer to a method list, such as r->allowed_methods.
454
 * @return  None.
455
 */
456
AP_DECLARE(void) ap_clear_method_list(ap_method_list_t *l);
457
458
/**
459
 * Set the content type for this request (r->content_type).
460
 * @param r The current request
461
 * @param ct The new content type
462
 * @warning This function must be called to set r->content_type in order
463
 * for the AddOutputFilterByType directive to work correctly.
464
 */
465
AP_DECLARE(void) ap_set_content_type(request_rec *r, const char *ct);
466
467
/**
468
 * Set the content type for this request (r->content_type).
469
 * @param r The current request
470
 * @param ct The new content type
471
 * @param trusted If non-zero, The content-type should come from a
472
 *        trusted source such as server configuration rather
473
 *        than application output.
474
 * for the AddOutputFilterByType directive to work correctly.
475
 */
476
AP_DECLARE(void) ap_set_content_type_ex(request_rec *r, const char *ct, int trusted);
477
478
/**
479
 * Set the Accept-Ranges header for this response
480
 * @param r The current request
481
 */
482
AP_DECLARE(void) ap_set_accept_ranges(request_rec *r);
483
484
485
/* Hmmm... could macrofy these for now, and maybe forever, though the
486
 * definitions of the macros would get a whole lot hairier.
487
 */
488
489
/**
490
 * Output one character for this request
491
 * @param c the character to output
492
 * @param r the current request
493
 * @return The number of bytes sent
494
 */
495
AP_DECLARE(int) ap_rputc(int c, request_rec *r);
496
497
/**
498
 * Write a buffer for the current request
499
 * @param buf The buffer to write
500
 * @param nbyte The number of bytes to send from the buffer
501
 * @param r The current request
502
 * @return The number of bytes sent
503
 */
504
AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r);
505
506
/**
507
 * Output a string for the current request
508
 * @param str The string to output
509
 * @param r The current request
510
 * @return The number of bytes sent
511
 * @note ap_rputs may be implemented as macro or inline function
512
 */
513
static APR_INLINE int ap_rputs(const char *str, request_rec *r)
514
0
{
515
0
    apr_size_t len;
516
0
517
0
    len = strlen(str);
518
0
519
0
    for (;;) {
520
0
        if (len <= INT_MAX) {
521
0
            return ap_rwrite(str, (int)len, r);
522
0
        }
523
0
        else {
524
0
            int rc;
525
0
526
0
            rc = ap_rwrite(str, INT_MAX, r);
527
0
            if (rc < 0) {
528
0
                return rc;
529
0
            }
530
0
            else {
531
0
                str += INT_MAX;
532
0
                len -= INT_MAX;
533
0
            }
534
0
        }
535
0
    }
536
0
}
Unexecuted instantiation: core.c:ap_rputs
Unexecuted instantiation: request.c:ap_rputs
Unexecuted instantiation: ssl.c:ap_rputs
Unexecuted instantiation: core_filters.c:ap_rputs
Unexecuted instantiation: util_expr_eval.c:ap_rputs
Unexecuted instantiation: config.c:ap_rputs
Unexecuted instantiation: vhost.c:ap_rputs
Unexecuted instantiation: util.c:ap_rputs
Unexecuted instantiation: util_etag.c:ap_rputs
Unexecuted instantiation: util_script.c:ap_rputs
Unexecuted instantiation: connection.c:ap_rputs
Unexecuted instantiation: mpm_common.c:ap_rputs
Unexecuted instantiation: scoreboard.c:ap_rputs
Unexecuted instantiation: protocol.c:ap_rputs
Unexecuted instantiation: eor_bucket.c:ap_rputs
Unexecuted instantiation: headers_bucket.c:ap_rputs
Unexecuted instantiation: error_bucket.c:ap_rputs
Unexecuted instantiation: http_core.c:ap_rputs
Unexecuted instantiation: http_protocol.c:ap_rputs
Unexecuted instantiation: http_request.c:ap_rputs
Unexecuted instantiation: http_filters.c:ap_rputs
Unexecuted instantiation: chunk_filter.c:ap_rputs
Unexecuted instantiation: byterange_filter.c:ap_rputs
Unexecuted instantiation: event.c:ap_rputs
537
538
/**
539
 * Write an unspecified number of strings to the request
540
 * @param r The current request
541
 * @param ... The strings to write
542
 * @return The number of bytes sent
543
 */
544
AP_DECLARE_NONSTD(int) ap_rvputs(request_rec *r,...)
545
                       AP_FN_ATTR_SENTINEL;
546
547
/**
548
 * Output data to the client in a printf format
549
 * @param r The current request
550
 * @param fmt The format string
551
 * @param vlist The arguments to use to fill out the format string
552
 * @return The number of bytes sent
553
 */
554
AP_DECLARE(int) ap_vrprintf(request_rec *r, const char *fmt, va_list vlist);
555
556
/**
557
 * Output data to the client in a printf format
558
 * @param r The current request
559
 * @param fmt The format string
560
 * @param ... The arguments to use to fill out the format string
561
 * @return The number of bytes sent
562
 */
563
AP_DECLARE_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt,...)
564
                                __attribute__((format(printf,2,3)));
565
566
/**
567
 * Flush all of the data for the current request to the client
568
 * @param r The current request
569
 * @return 0 on success, -1 if an error occurred
570
 */
571
AP_DECLARE(int) ap_rflush(request_rec *r);
572
573
/**
574
 * Index used in custom_responses array for a specific error code
575
 * (only use outside protocol.c is in getting them configured).
576
 * @param status HTTP status code
577
 * @return The index of the response
578
 */
579
AP_DECLARE(int) ap_index_of_response(int status);
580
581
/**
582
 * Return the Status-Line for a given status code (excluding the
583
 * HTTP-Version field). If an invalid or unknown status code is
584
 * passed, "500 Internal Server Error" will be returned.
585
 * @param status The HTTP status code
586
 * @return The Status-Line
587
 */
588
AP_DECLARE(const char *) ap_get_status_line(int status);
589
590
/**
591
 * Return the Status-Line for a given status code (excluding the
592
 * HTTP-Version field). If an invalid status code is passed,
593
 * "500 Internal Server Error" will be returned, whereas an unknown
594
 * status will be returned like "xxx Status xxx".
595
 * @param p The pool to allocate from when status is unknown
596
 * @param status The HTTP status code
597
 * @return The Status-Line
598
 */
599
AP_DECLARE(const char *) ap_get_status_line_ex(apr_pool_t *p, int status);
600
601
/* Reading a block of data from the client connection (e.g., POST arg) */
602
603
/**
604
 * Setup the client to allow Apache to read the request body.
605
 * @param r The current request
606
 * @param read_policy How the server should interpret a chunked
607
 *                    transfer-encoding.  One of: <pre>
608
 *    REQUEST_NO_BODY          Send 413 error if message has any body
609
 *    REQUEST_CHUNKED_ERROR    Send 411 error if body without Content-Length
610
 *    REQUEST_CHUNKED_DECHUNK  If chunked, remove the chunks for me.
611
 * </pre>
612
 * @return either OK or an error code
613
 */
614
AP_DECLARE(int) ap_setup_client_block(request_rec *r, int read_policy);
615
616
/**
617
 * Determine if the client has sent any data.  This also sends a
618
 * 100 Continue response to HTTP/1.1 clients, so modules should not be called
619
 * until the module is ready to read content.
620
 * @warning Never call this function more than once.
621
 * @param r The current request
622
 * @return 0 if there is no message to read, 1 otherwise
623
 */
624
AP_DECLARE(int) ap_should_client_block(request_rec *r);
625
626
/**
627
 * Call this in a loop.  It will put data into a buffer and return the length
628
 * of the input block
629
 * @param r The current request
630
 * @param buffer The buffer in which to store the data
631
 * @param bufsiz The size of the buffer
632
 * @return Number of bytes inserted into the buffer.  When done reading, 0
633
 *         if EOF, or -1 if there was an error
634
 */
635
AP_DECLARE(long) ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz);
636
637
/**
638
 * Map specific APR codes returned by the filter stack to HTTP error
639
 * codes, or the default status code provided. Use it as follows:
640
 *
641
 * return ap_map_http_request_error(rv, HTTP_BAD_REQUEST);
642
 *
643
 * If the filter has already handled the error, AP_FILTER_ERROR will
644
 * be returned, which is cleanly passed through.
645
 *
646
 * These mappings imply that the filter stack is reading from the
647
 * downstream client, the proxy will map these codes differently.
648
 * @param rv APR status code
649
 * @param status Default HTTP code should the APR code not be recognised
650
 * @return Mapped HTTP status code
651
 */
652
AP_DECLARE(int) ap_map_http_request_error(apr_status_t rv, int status);
653
654
/**
655
 * In HTTP/1.1, any method can have a body.  However, most GET handlers
656
 * wouldn't know what to do with a request body if they received one.
657
 * This helper routine tests for and reads any message body in the request,
658
 * simply discarding whatever it receives.  We need to do this because
659
 * failing to read the request body would cause it to be interpreted
660
 * as the next request on a persistent connection.
661
 * @param r The current request
662
 * @return error status if request is malformed, OK otherwise
663
 */
664
AP_DECLARE(int) ap_discard_request_body(request_rec *r);
665
666
/**
667
 * Setup the output headers so that the client knows how to authenticate
668
 * itself the next time, if an authentication request failed.
669
 * @param r The current request
670
 */
671
AP_DECLARE(void) ap_note_auth_failure(request_rec *r);
672
673
/**
674
 * @deprecated @see ap_note_auth_failure
675
 */
676
AP_DECLARE(void) ap_note_basic_auth_failure(request_rec *r);
677
678
/**
679
 * @deprecated @see ap_note_auth_failure
680
 */
681
AP_DECLARE(void) ap_note_digest_auth_failure(request_rec *r);
682
683
/**
684
 * This hook allows modules to add support for a specific auth type to
685
 * ap_note_auth_failure
686
 * @param r the current request
687
 * @param auth_type the configured auth_type
688
 * @return OK, DECLINED
689
 */
690
AP_DECLARE_HOOK(int, note_auth_failure, (request_rec *r, const char *auth_type))
691
692
/**
693
 * Get the password from the request headers. This function has multiple side
694
 * effects due to its prior use in the old authentication framework, including
695
 * setting r->user (which is supposed to indicate that the user in question has
696
 * been authenticated for the current request).
697
 *
698
 * Modules which call ap_get_basic_auth_pw() during the authentication phase
699
 * MUST either immediately authenticate the user after the call, or else stop
700
 * the request immediately with an error response, to avoid incorrectly
701
 * authenticating the current request. (See CVE-2017-3167.) The replacement
702
 * ap_get_basic_auth_components() API should be preferred.
703
 *
704
 * @deprecated @see ap_get_basic_auth_components
705
 * @param r The current request
706
 * @param pw The password as set in the headers
707
 * @return 0 (OK) if it set the 'pw' argument (and assured
708
 *         a correct value in r->user); otherwise it returns
709
 *         an error code, either HTTP_INTERNAL_SERVER_ERROR if things are
710
 *         really confused, HTTP_UNAUTHORIZED if no authentication at all
711
 *         seemed to be in use, or DECLINED if there was authentication but
712
 *         it wasn't Basic (in which case, the caller should presumably
713
 *         decline as well).
714
 */
715
AP_DECLARE(int) ap_get_basic_auth_pw(request_rec *r, const char **pw);
716
717
0
#define AP_GET_BASIC_AUTH_PW_NOTE "AP_GET_BASIC_AUTH_PW_NOTE"
718
719
/**
720
 * Get the username and/or password from the request's Basic authentication
721
 * headers. Unlike ap_get_basic_auth_pw(), calling this function has no side
722
 * effects on the passed request_rec.
723
 *
724
 * @param r The current request
725
 * @param username If not NULL, set to the username sent by the client
726
 * @param password If not NULL, set to the password sent by the client
727
 * @return APR_SUCCESS if the credentials were successfully parsed and returned;
728
 *         APR_EINVAL if there was no authentication header sent or if the
729
 *         client was not using the Basic authentication scheme. username and
730
 *         password are unchanged on failure.
731
 */
732
AP_DECLARE(apr_status_t) ap_get_basic_auth_components(const request_rec *r,
733
                                                      const char **username,
734
                                                      const char **password);
735
736
/**
737
 * parse_uri: break apart the uri
738
 * @warning Side Effects:
739
 *    @li sets r->args to rest after '?' (or NULL if no '?')
740
 *    @li sets r->uri to request uri (without r->args part)
741
 *    @li sets r->hostname (if not set already) from request (scheme://host:port)
742
 * @param r The current request
743
 * @param uri The uri to break apart
744
 */
745
AP_CORE_DECLARE(void) ap_parse_uri(request_rec *r, const char *uri);
746
747
0
#define AP_GETLINE_FOLD      (1 << 0) /* Whether to merge continuation lines */
748
0
#define AP_GETLINE_CRLF      (1 << 1) /* Whether line ends must be CRLF */
749
0
#define AP_GETLINE_NOSPC_EOL (1 << 2) /* Whether to consume up to and including
750
                                         the end of line on APR_ENOSPC */
751
0
#define AP_GETLINE_NONBLOCK  (1 << 3) /* Whether to read non-blocking */
752
753
/**
754
 * Get the next line of input for the request
755
 * @param s The buffer into which to read the line
756
 * @param n The size of the buffer
757
 * @param r The request
758
 * @param flags Bit mask of AP_GETLINE_* options
759
 * @return The length of the line, if successful
760
 *         n, if the line is too big to fit in the buffer
761
 *         -1 for miscellaneous errors
762
 */
763
AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int flags);
764
765
/**
766
 * Get the next line from an input filter
767
 *
768
 * @param s Pointer to the pointer to the buffer into which the line
769
 *          should be read; if *s==NULL, a buffer of the necessary size
770
 *          to hold the data will be allocated from \p p
771
 * @param n The size of the buffer
772
 * @param read The length of the line.
773
 * @param f Input filter to read from
774
 * @param flags Bit mask of AP_GETLINE_* options
775
 * @param bb Working brigade to use when reading buckets
776
 * @param p The pool to allocate the buffer from (if needed)
777
 * @return APR_SUCCESS, if successful
778
 *         APR_ENOSPC, if the line is too big to fit in the buffer
779
 *         Other errors where appropriate
780
 */
781
AP_DECLARE(apr_status_t) ap_fgetline(char **s, apr_size_t n,
782
                                     apr_size_t *read, ap_filter_t *f,
783
                                     int flags, apr_bucket_brigade *bb,
784
                                     apr_pool_t *p);
785
786
/**
787
 * @see ap_fgetline
788
 *
789
 * Note: genuinely calls, ap_fgetline(s, n, read, r->proto_input_filters,
790
 *                                    flags, bb, r->pool)
791
 */
792
AP_DECLARE(apr_status_t) ap_rgetline(char **s, apr_size_t n,
793
                                     apr_size_t *read, request_rec *r,
794
                                     int flags, apr_bucket_brigade *bb);
795
796
/**
797
 * Get the method number associated with the given string, assumed to
798
 * contain an HTTP method.  Returns M_INVALID if not recognized.
799
 * @param method A string containing a valid HTTP method
800
 * @return The method number
801
 */
802
AP_DECLARE(int) ap_method_number_of(const char *method);
803
804
/**
805
 * Get the method name associated with the given internal method
806
 * number.  Returns NULL if not recognized.
807
 * @param p A pool to use for temporary allocations.
808
 * @param methnum An integer value corresponding to an internal method number
809
 * @return The name corresponding to the method number
810
 */
811
AP_DECLARE(const char *) ap_method_name_of(apr_pool_t *p, int methnum);
812
813
814
/* Hooks */
815
/*
816
 * pre_read_request --- run right before read_request_line(),
817
 *                  and not run during any subrequests.
818
 */
819
/**
820
 * This hook allows modules to affect the request or connection immediately before
821
 * the request has been read, and before any other phases have been processes.
822
 * @param r The current request of the soon-to-be-read request
823
 * @param c The connection
824
 * @return None/void
825
 */
826
AP_DECLARE_HOOK(void,pre_read_request,(request_rec *r, conn_rec *c))
827
828
/*
829
 * post_read_request --- run right after read_request or internal_redirect,
830
 *                  and not run during any subrequests.
831
 */
832
/**
833
 * This hook allows modules to affect the request immediately after the request
834
 * has been read, and before any other phases have been processes.  This allows
835
 * modules to make decisions based upon the input header fields
836
 * @param r The current request
837
 * @return OK or DECLINED
838
 */
839
AP_DECLARE_HOOK(int,post_read_request,(request_rec *r))
840
841
/**
842
 * This hook allows modules to perform any module-specific logging activities
843
 * over and above the normal server things.
844
 * @param r The current request
845
 * @return OK, DECLINED, or HTTP_...
846
 */
847
AP_DECLARE_HOOK(int,log_transaction,(request_rec *r))
848
849
/**
850
 * This hook allows modules to retrieve the http scheme for a request.  This
851
 * allows Apache modules to easily extend the schemes that Apache understands
852
 * @param r The current request
853
 * @return The http scheme from the request
854
 */
855
AP_DECLARE_HOOK(const char *,http_scheme,(const request_rec *r))
856
857
/**
858
 * Return the default port from the current request
859
 * @param r The current request
860
 * @return The current port
861
 */
862
AP_DECLARE_HOOK(apr_port_t,default_port,(const request_rec *r))
863
864
865
0
#define AP_PROTOCOL_HTTP1        "http/1.1"
866
867
/**
868
 * Determine the list of protocols available for a connection/request. This may
869
 * be collected with or without any request sent, in which case the request is 
870
 * NULL. Or it may be triggered by the request received, e.g. through the 
871
 * "Upgrade" header.
872
 *
873
 * This hook will be run whenever protocols are being negotiated (ALPN as
874
 * one example). It may also be invoked at other times, e.g. when the server
875
 * wants to advertise protocols it is capable of switching to.
876
 * 
877
 * The identifiers for protocols are taken from the TLS extension type ALPN:
878
 * https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xml
879
 *
880
 * If no protocols are added to the proposals, the server not perform any
881
 * switch. If the protocol selected from the proposals is the protocol
882
 * already in place, also no protocol switch will be invoked.
883
 *
884
 * The client may already have announced the protocols it is willing to
885
 * accept. These will then be listed as offers. This parameter may also
886
 * be NULL, indicating that offers from the client are not known and
887
 * the hooks should propose all protocols that are valid for the
888
 * current connection/request.
889
 *
890
 * All hooks are run, unless one returns an error. Proposals may contain
891
 * duplicates. The order in which proposals are added is usually ignored.
892
 * 
893
 * @param c The current connection
894
 * @param r The current request or NULL
895
 * @param s The server/virtual host selected
896
 * @param offers A list of protocol identifiers offered by the client or
897
 *               NULL to indicated that the hooks are free to propose 
898
 * @param proposals The list of protocol identifiers proposed by the hooks
899
 * @return OK or DECLINED
900
 */
901
AP_DECLARE_HOOK(int,protocol_propose,(conn_rec *c, request_rec *r,
902
                                      server_rec *s,
903
                                      const apr_array_header_t *offers,
904
                                      apr_array_header_t *proposals))
905
906
/**
907
 * Perform a protocol switch on the connection. The exact requirements for
908
 * that depend on the protocol in place and the one switched to. The first 
909
 * protocol module to handle the switch is the last module run.
910
 * 
911
 * For a connection level switch (r == NULL), the handler must on return
912
 * leave the conn_rec in a state suitable for processing the switched
913
 * protocol, e.g. correct filters in place.
914
 *
915
 * For a request triggered switch (r != NULL), the protocol switch is done
916
 * before the response is sent out. When switching from "http/1.1" via Upgrade
917
 * header, the 101 intermediate response will have been sent. The
918
 * hook needs then to process the connection until it can be closed. Which
919
 * the server will enforce on hook return.
920
 * Any error the hook might encounter must already be sent by the hook itself
921
 * to the client in whatever form the new protocol requires.
922
 *
923
 * @param c The current connection
924
 * @param r The current request or NULL
925
 * @param s The server/virtual host selected
926
 * @param protocol The protocol identifier we try to switch to
927
 * @return OK or DECLINED
928
 */
929
AP_DECLARE_HOOK(int,protocol_switch,(conn_rec *c, request_rec *r,
930
                                     server_rec *s,
931
                                     const char *protocol))
932
933
/**
934
 * Return the protocol used on the connection. Modules implementing
935
 * protocol switching must register here and return the correct protocol
936
 * identifier for connections they switched.
937
 *
938
 * To find out the protocol for the current connection, better call
939
 * @see ap_get_protocol which internally uses this hook.
940
 *
941
 * @param c The current connection
942
 * @return The identifier of the protocol in place or NULL
943
 */
944
AP_DECLARE_HOOK(const char *,protocol_get,(const conn_rec *c))
945
946
/**
947
 * Get the protocols that the connection and optional request may
948
 * upgrade to - besides the protocol currently active on the connection. These
949
 * values may be used to announce to a client what choices it has.
950
 *
951
 * If report_all == 0, only protocols more preferable than the one currently
952
 * being used, are reported. Otherwise, all available protocols beside the
953
 * current one are being reported.
954
 *
955
 * @param c The current connection
956
 * @param r The current request or NULL
957
 * @param s The server/virtual host selected or NULL
958
 * @param report_all include also protocols less preferred than the current one
959
 * @param pupgrades on return, possible protocols to upgrade to in descending order 
960
 *                 of preference. Maybe NULL if none are available.    
961
 */
962
AP_DECLARE(apr_status_t) ap_get_protocol_upgrades(conn_rec *c, request_rec *r, 
963
                                                  server_rec *s, int report_all, 
964
                                                  const apr_array_header_t **pupgrades);
965
                                                  
966
/**
967
 * Select a protocol for the given connection and optional request. Will return
968
 * the protocol identifier selected which may be the protocol already in place
969
 * on the connection. The selected protocol will be NULL if non of the given
970
 * choices could be agreed upon (e.g. no proposal as made).
971
 *
972
 * A special case is where the choices itself is NULL (instead of empty). In
973
 * this case there are no restrictions imposed on protocol selection.
974
 *
975
 * @param c The current connection
976
 * @param r The current request or NULL
977
 * @param s The server/virtual host selected
978
 * @param choices A list of protocol identifiers, normally the client's wishes
979
 * @return The selected protocol or NULL if no protocol could be agreed upon
980
 */
981
AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r, 
982
                                            server_rec *s,
983
                                            const apr_array_header_t *choices);
984
985
/**
986
 * Perform the actual protocol switch. The protocol given must have been
987
 * selected before on the very same connection and request pair.
988
 *
989
 * @param c The current connection
990
 * @param r The current request or NULL
991
 * @param s The server/virtual host selected
992
 * @param protocol the protocol to switch to
993
 * @return APR_SUCCESS, if caller may continue processing as usual
994
 *         APR_EOF,     if caller needs to stop processing the connection
995
 *         APR_EINVAL,  if the protocol is already in place
996
 *         APR_NOTIMPL, if no module performed the switch
997
 *         Other errors where appropriate
998
 */
999
AP_DECLARE(apr_status_t) ap_switch_protocol(conn_rec *c, request_rec *r, 
1000
                                            server_rec *s,
1001
                                            const char *protocol);
1002
1003
/**
1004
 * Call the protocol_get hook to determine the protocol currently in use
1005
 * for the given connection.
1006
 *
1007
 * Unless another protocol has been switch to, will default to
1008
 * @see AP_PROTOCOL_HTTP1 and modules implementing a  new protocol must
1009
 * report a switched connection via the protocol_get hook.
1010
 *
1011
 * @param c The connection to determine the protocol for
1012
 * @return the protocol in use, never NULL
1013
 */
1014
AP_DECLARE(const char *) ap_get_protocol(conn_rec *c);
1015
1016
/**
1017
 * Check if the given protocol is an allowed choice on the given
1018
 * combination of connection, request and server. 
1019
 *
1020
 * When server is NULL, it is taken from request_rec, unless
1021
 * request_rec is NULL. Then it is taken from the connection base
1022
 * server.
1023
 *
1024
 * @param c The current connection
1025
 * @param r The current request or NULL
1026
 * @param s The server/virtual host selected or NULL
1027
 * @param protocol the protocol to switch to
1028
 * @return != 0 iff protocol is allowed
1029
 */
1030
AP_DECLARE(int) ap_is_allowed_protocol(conn_rec *c, request_rec *r,
1031
                                       server_rec *s, const char *protocol);
1032
1033
/** @see ap_bucket_type_error */
1034
typedef struct ap_bucket_error ap_bucket_error;
1035
1036
/**
1037
 * @struct ap_bucket_error
1038
 * @brief  A bucket referring to an HTTP error
1039
 *
1040
 * This bucket can be passed down the filter stack to indicate that an
1041
 * HTTP error occurred while running a filter.  In order for this bucket
1042
 * to be used successfully, it MUST be sent as the first bucket in the
1043
 * first brigade to be sent from a given filter.
1044
 */
1045
struct ap_bucket_error {
1046
    /** Number of buckets using this memory */
1047
    apr_bucket_refcount refcount;
1048
    /** The error code */
1049
    int status;
1050
    /** The error string */
1051
    const char    *data;
1052
};
1053
1054
/** @see ap_bucket_type_error */
1055
AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_error;
1056
1057
/**
1058
 * Determine if a bucket is an error bucket
1059
 * @param e The bucket to inspect
1060
 * @return true or false
1061
 */
1062
0
#define AP_BUCKET_IS_ERROR(e)         (e->type == &ap_bucket_type_error)
1063
1064
/**
1065
 * Make the bucket passed in an error bucket
1066
 * @param b The bucket to make into an error bucket
1067
 * @param error The HTTP error code to put in the bucket.
1068
 * @param buf An optional error string to put in the bucket.
1069
 * @param p A pool to allocate out of.
1070
 * @return The new bucket, or NULL if allocation failed
1071
 */
1072
AP_DECLARE(apr_bucket *) ap_bucket_error_make(apr_bucket *b, int error,
1073
                const char *buf, apr_pool_t *p);
1074
1075
/**
1076
 * Create a bucket referring to an HTTP error.
1077
 * @param error The HTTP error code to put in the bucket.
1078
 * @param buf An optional error string to put in the bucket.
1079
 * @param p A pool to allocate the error string out of.
1080
 * @param list The bucket allocator from which to allocate the bucket
1081
 * @return The new bucket, or NULL if allocation failed
1082
 */
1083
AP_DECLARE(apr_bucket *) ap_bucket_error_create(int error, const char *buf,
1084
                                                apr_pool_t *p,
1085
                                                apr_bucket_alloc_t *list);
1086
1087
/** @see ap_bucket_type_request */
1088
typedef struct ap_bucket_request ap_bucket_request;
1089
1090
/**
1091
 * @struct ap_bucket_request
1092
 * @brief  A bucket referring to a HTTP request
1093
 *
1094
 */
1095
struct ap_bucket_request {
1096
    /** Number of buckets using this memory */
1097
    apr_bucket_refcount refcount;
1098
    apr_pool_t *pool; /* pool that holds the contents, not for modification */
1099
    const char *method; /* request method */
1100
    const char *uri; /* request uri */
1101
    const char *protocol; /* request protocol */
1102
    apr_table_t *headers; /* request headers */
1103
};
1104
1105
/** @see ap_bucket_type_request */
1106
AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_request;
1107
1108
/**
1109
 * Determine if a bucket is a request bucket
1110
 * @param e The bucket to inspect
1111
 * @return true or false
1112
 */
1113
0
#define AP_BUCKET_IS_REQUEST(e)         (e->type == &ap_bucket_type_request)
1114
1115
/**
1116
 * Make the bucket passed in a request bucket
1117
 * Copies all parameters to the given pool.
1118
 * @param b The bucket to make into a request bucket
1119
 * @param method the HTTP method
1120
 * @param uri the uri requested
1121
 * @param protocol the protocol requested
1122
 * @param headers the table of response headers.
1123
 * @param p A pool to allocate out of.
1124
 * @return The new bucket, or NULL if allocation failed
1125
 */
1126
AP_DECLARE(apr_bucket *) ap_bucket_request_make(
1127
            apr_bucket *b,
1128
            const char *method,
1129
            const char *uri,
1130
            const char *protocol,
1131
            apr_table_t *headers,
1132
            apr_pool_t *p);
1133
1134
/**
1135
 * Make the bucket passed in a request bucket
1136
 * Uses all paramters without copying.
1137
 * @param b The bucket to make into a request bucket
1138
 * @param method the HTTP method
1139
 * @param uri the uri requested
1140
 * @param protocol the protocol requested
1141
 * @param headers the table of response headers.
1142
 * @param p A pool to allocate out of.
1143
 * @return The new bucket, or NULL if allocation failed
1144
 */
1145
AP_DECLARE(apr_bucket *) ap_bucket_request_maken(
1146
            apr_bucket *b,
1147
            const char *method,
1148
            const char *uri,
1149
            const char *protocol,
1150
            apr_table_t *headers,
1151
            apr_pool_t *p);
1152
1153
/**
1154
 * Create a bucket referring to a HTTP request.
1155
 * Copies all parameters to the given pool.
1156
 * @param method the HTTP method
1157
 * @param uri the uri requested
1158
 * @param protocol the protocol requested
1159
 * @param headers the table of response headers.
1160
 * @param p A pool to allocate the error string out of.
1161
 * @param list The bucket allocator from which to allocate the bucket
1162
 * @return The new bucket, or NULL if allocation failed
1163
 */
1164
AP_DECLARE(apr_bucket *) ap_bucket_request_create(
1165
            const char *method,
1166
            const char *uri,
1167
            const char *protocol,
1168
            apr_table_t *headers,
1169
            apr_pool_t *p,
1170
            apr_bucket_alloc_t *list);
1171
1172
/**
1173
 * Create a bucket referring to a HTTP request.
1174
 * Uses all paramters without copying.
1175
 * @param method the HTTP method
1176
 * @param uri the uri requested
1177
 * @param protocol the protocol requested
1178
 * @param headers the HTTP response headers.
1179
 * @param p A pool to allocate the error string out of.
1180
 * @param list The bucket allocator from which to allocate the bucket
1181
 * @return The new bucket, or NULL if allocation failed
1182
 */
1183
AP_DECLARE(apr_bucket *) ap_bucket_request_createn(
1184
            const char *method,
1185
            const char *uri,
1186
            const char *protocol,
1187
            apr_table_t *headers,
1188
            apr_pool_t *p,
1189
            apr_bucket_alloc_t *list);
1190
1191
/**
1192
 * Clone a request bucket into another pool/bucket_alloc that may
1193
 * have a separate lifetime than the source bucket/pool.
1194
 * @param source the request bucket to clone
1195
 * @param p A pool to allocate the data out of.
1196
 * @param list The bucket allocator from which to allocate the bucket
1197
 * @return The new bucket, or NULL if allocation failed
1198
 */
1199
AP_DECLARE(apr_bucket *) ap_bucket_request_clone(apr_bucket *source,
1200
                                                  apr_pool_t *p,
1201
                                                  apr_bucket_alloc_t *list);
1202
1203
/** @see ap_bucket_type_response */
1204
typedef struct ap_bucket_response ap_bucket_response;
1205
1206
/**
1207
 * @struct ap_bucket_response
1208
 * @brief  A bucket referring to a HTTP response
1209
 *
1210
 */
1211
struct ap_bucket_response {
1212
    /** Number of buckets using this memory */
1213
    apr_bucket_refcount refcount;
1214
    apr_pool_t *pool; /* pool that holds the contents, not for modification */
1215
    int status; /* The status code */
1216
    const char *reason; /* The optional HTTP reason for the status. */
1217
    apr_table_t *headers; /* The response headers */
1218
    apr_table_t *notes; /* internal notes about the response */
1219
};
1220
1221
/** @see ap_bucket_type_headers */
1222
AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_response;
1223
1224
/**
1225
 * Determine if a bucket is a response bucket
1226
 * @param e The bucket to inspect
1227
 * @return true or false
1228
 */
1229
0
#define AP_BUCKET_IS_RESPONSE(e)         (e->type == &ap_bucket_type_response)
1230
1231
/**
1232
 * Make the bucket passed in a response bucket
1233
 * @param b The bucket to make into a response bucket
1234
 * @param status The HTTP status code of the response.
1235
 * @param reason textual description of status, can be NULL.
1236
 * @param headers the table of response headers.
1237
 * @param notes internal notes on the response
1238
 * @param p A pool to allocate out of.
1239
 * @return The new bucket, or NULL if allocation failed
1240
 */
1241
AP_DECLARE(apr_bucket *) ap_bucket_response_make(apr_bucket *b, int status,
1242
            const char *reason, apr_table_t *headers,
1243
            apr_table_t *notes, apr_pool_t *p);
1244
1245
/**
1246
 * Create a bucket referring to a HTTP response.
1247
 * @param status The HTTP status code.
1248
 * @param reason textual description of status, can be NULL.
1249
 * @param headers the HTTP response headers.
1250
 * @param notes internal notes on the response
1251
 * @param p A pool to allocate the error string out of.
1252
 * @param list The bucket allocator from which to allocate the bucket
1253
 * @return The new bucket, or NULL if allocation failed
1254
 */
1255
AP_DECLARE(apr_bucket *) ap_bucket_response_create(
1256
            int status, const char *reason,
1257
            apr_table_t *headers,
1258
            apr_table_t *notes,
1259
            apr_pool_t *p,
1260
            apr_bucket_alloc_t *list);
1261
1262
/**
1263
 * Clone a RESPONSE bucket into another pool/bucket_alloc that may
1264
 * have a separate lifetime than the source bucket/pool.
1265
 * @param source the response bucket to clone
1266
 * @param p A pool to allocate the data out of.
1267
 * @param list The bucket allocator from which to allocate the bucket
1268
 * @return The new bucket, or NULL if allocation failed
1269
 */
1270
AP_DECLARE(apr_bucket *) ap_bucket_response_clone(apr_bucket *source,
1271
                                                  apr_pool_t *p,
1272
                                                  apr_bucket_alloc_t *list);
1273
1274
/** @see ap_bucket_type_headers */
1275
typedef struct ap_bucket_headers ap_bucket_headers;
1276
1277
/**
1278
 * @struct ap_bucket_headers
1279
 * @brief  A bucket referring to an HTTP header set
1280
 *
1281
 */
1282
struct ap_bucket_headers {
1283
    /** Number of buckets using this memory */
1284
    apr_bucket_refcount refcount;
1285
    apr_pool_t *pool; /* pool that holds the contents, not for modification */
1286
    apr_table_t *headers; /* The headers */
1287
1288
};
1289
1290
/** @see ap_bucket_type_headers */
1291
AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_headers;
1292
1293
/**
1294
 * Determine if a bucket is an headers bucket
1295
 * @param e The bucket to inspect
1296
 * @return true or false
1297
 */
1298
0
#define AP_BUCKET_IS_HEADERS(e)         (e->type == &ap_bucket_type_headers)
1299
1300
/**
1301
 * Make the bucket passed in a headers bucket
1302
 * @param b The bucket to make into a headers bucket
1303
 * @param headers the table of headers.
1304
 * @param p A pool to allocate out of.
1305
 * @return The new bucket, or NULL if allocation failed
1306
 */
1307
AP_DECLARE(apr_bucket *) ap_bucket_headers_make(apr_bucket *b,
1308
                apr_table_t *headers, apr_pool_t *p);
1309
1310
/**
1311
 * Create a bucket referring to a table of HTTP headers.
1312
 * @param headers the HTTP headers in the bucket.
1313
 * @param p A pool to allocate the error string out of.
1314
 * @param list The bucket allocator from which to allocate the bucket
1315
 * @return The new bucket, or NULL if allocation failed
1316
 */
1317
AP_DECLARE(apr_bucket *) ap_bucket_headers_create(apr_table_t *headers,
1318
                                                  apr_pool_t *p,
1319
                                                  apr_bucket_alloc_t *list);
1320
1321
/**
1322
 * Clone a HEADER bucket into another pool/bucket_alloc that may
1323
 * have a separate lifetime than the source bucket/pool.
1324
 * @param source the header bucket to clone
1325
 * @param p A pool to allocate the data out of.
1326
 * @param list The bucket allocator from which to allocate the bucket
1327
 * @return The new bucket, or NULL if allocation failed
1328
 */
1329
AP_DECLARE(apr_bucket *) ap_bucket_headers_clone(apr_bucket *source,
1330
                                                 apr_pool_t *p,
1331
                                                 apr_bucket_alloc_t *list);
1332
1333
AP_DECLARE_NONSTD(apr_status_t) ap_byterange_filter(ap_filter_t *f, apr_bucket_brigade *b);
1334
AP_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, apr_bucket_brigade *b);
1335
AP_DECLARE_NONSTD(apr_status_t) ap_content_length_filter(ap_filter_t *,
1336
                                                              apr_bucket_brigade *);
1337
AP_DECLARE_NONSTD(apr_status_t) ap_old_write_filter(ap_filter_t *f, apr_bucket_brigade *b);
1338
1339
/**
1340
 * Sett up the protocol fields for subsidiary requests
1341
 * @param rnew New Sub Request
1342
 * @param r current request
1343
 */
1344
AP_DECLARE(void) ap_set_sub_req_protocol(request_rec *rnew, const request_rec *r);
1345
1346
/**
1347
 * A wrapup function to keep the internal accounting straight.
1348
 * Indicates that there is no more content coming.
1349
 * @param sub_r Subrequest that is now compete
1350
 */
1351
AP_DECLARE(void) ap_finalize_sub_req_protocol(request_rec *sub_r);
1352
1353
/**
1354
 * Set standard response headers, such as `Date` and `Server`
1355
 * in r->headers_out. Takes care of precedence of existing
1356
 * values from proxied requests.
1357
 */
1358
AP_DECLARE(void) ap_set_std_response_headers(request_rec *r);
1359
1360
/**
1361
 * Send an interim (HTTP 1xx) response immediately.
1362
 * @param r The request
1363
 * @param send_headers Whether to send&clear headers in r->headers_out
1364
 */
1365
AP_DECLARE(void) ap_send_interim_response(request_rec *r, int send_headers);
1366
1367
/**
1368
 * Append a header in HTTP/1.1 format to the brigade.
1369
 * @param b the brigade to append to
1370
 * @param p the pool to use
1371
 * @param name the name of the header field
1372
 * @param value the value of the header field
1373
 */
1374
AP_DECLARE(apr_status_t) ap_h1_append_header(apr_bucket_brigade *b,
1375
                                             apr_pool_t *pool,
1376
                                             const char *name, const char *value);
1377
/**
1378
 * Append the headers in HTTP/1.1 format to the brigade.
1379
 * @param b the brigade to append to
1380
 * @param r the request this is done for (pool and logging)
1381
 * @param headers the headers to append
1382
 */
1383
AP_DECLARE(apr_status_t) ap_h1_append_headers(apr_bucket_brigade *b,
1384
                                              request_rec *r,
1385
                                              apr_table_t *headers);
1386
1387
/**
1388
 * Append the HTTP/1.1 header termination (empty CRLF) to the brigade.
1389
 * @param b the brigade to append to
1390
 */
1391
AP_DECLARE(apr_status_t) ap_h1_terminate_header(apr_bucket_brigade *b);
1392
1393
/**
1394
 * Insert/Append the last chunk in a HTTP/1.1 Transfer-Encoding chunked.
1395
 * @param b the brigade to add the chunk to
1396
 * @param eos the bucket before to add or NULL for insert at tail
1397
 * @param r the request handled
1398
 * @param trailers table of trailers or NULL
1399
 */
1400
AP_DECLARE(void) ap_h1_add_end_chunk(apr_bucket_brigade *b,
1401
                                     apr_bucket *eos,
1402
                                     request_rec *r,
1403
                                     apr_table_t *trailers);
1404
1405
#ifdef __cplusplus
1406
}
1407
#endif
1408
1409
#endif  /* !APACHE_HTTP_PROTOCOL_H */
1410
/** @} */