Apache HTTPD
mod_asis.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#include "apr_strings.h"
18#include "ap_config.h"
19#include "httpd.h"
20#include "http_config.h"
21#include "http_protocol.h"
22#include "http_log.h"
23#include "util_script.h"
24#include "http_main.h"
25#include "http_request.h"
26
27#include "mod_core.h"
28
29#define ASIS_MAGIC_TYPE "httpd/send-as-is"
30
32{
34 apr_status_t rv;
35 const char *location;
36
37 if (strcmp(r->handler, ASIS_MAGIC_TYPE) && strcmp(r->handler, "send-as-is")) {
38 return DECLINED;
39 }
40
42 if (r->method_number != M_GET) {
43 return DECLINED;
44 }
45
46 if (r->finfo.filetype == APR_NOFILE) {
48 "File does not exist: %s", r->filename);
49 return HTTP_NOT_FOUND;
50 }
51
52 if ((rv = apr_file_open(&f, r->filename, APR_READ,
55 "file permissions deny server access: %s", r->filename);
56 return HTTP_FORBIDDEN;
57 }
58
60 location = apr_table_get(r->headers_out, "Location");
61
62 if (location && location[0] == '/' &&
64
66
67 /* Internal redirect -- fake-up a pseudo-request */
68 r->status = HTTP_OK;
69
70 /* This redirect needs to be a GET no matter what the original
71 * method was.
72 */
73 r->method = "GET";
75
77 return OK;
78 }
79
80 if (!r->header_only) {
84 apr_off_t pos = 0;
85
86 rv = apr_file_seek(f, APR_CUR, &pos);
87 if (rv != APR_SUCCESS) {
89 "mod_asis: failed to find end-of-headers position "
90 "for %s", r->filename);
93 }
94
95 bb = apr_brigade_create(r->pool, c->bucket_alloc);
96 apr_brigade_insert_file(bb, f, pos, r->finfo.size - pos, r->pool);
97
98 b = apr_bucket_eos_create(c->bucket_alloc);
101 if (rv != APR_SUCCESS) {
103 "mod_asis: ap_pass_brigade failed for file %s", r->filename);
104 return AP_FILTER_ERROR;
105 }
106 }
107 else {
109 }
110
111 return OK;
112}
113
118
120{
122 NULL, /* create per-directory config structure */
123 NULL, /* merge per-directory config structures */
124 NULL, /* create per-server config structure */
125 NULL, /* merge per-server config structures */
126 NULL, /* command apr_table_t */
127 register_hooks /* register hooks */
128};
Symbol export macros and hook functions.
APR Strings library.
#define AP_DECLARE_MODULE(foo)
void ap_hook_handler(ap_HOOK_handler_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:170
request_rec * r
#define AP_FILTER_ERROR
Definition httpd.h:473
#define DECLINED
Definition httpd.h:457
#define OK
Definition httpd.h:456
apr_status_t ap_pass_brigade(ap_filter_t *filter, apr_bucket_brigade *bucket)
#define APLOGNO(n)
Definition http_log.h:117
#define APLOG_INFO
Definition http_log.h:70
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_ERR
Definition http_log.h:67
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_MODULE_INDEX
Definition http_log.h:168
void ap_internal_redirect_handler(const char *new_uri, request_rec *r)
int ap_scan_script_header_err_ex(request_rec *r, apr_file_t *f, char *buffer, int module_index)
apr_file_t * f
#define APR_BRIGADE_INSERT_TAIL(b, e)
#define APR_HOOK_MIDDLE
Definition apr_hooks.h:303
#define HTTP_OK
Definition httpd.h:490
#define HTTP_INTERNAL_SERVER_ERROR
Definition httpd.h:535
#define ap_is_HTTP_REDIRECT(x)
Definition httpd.h:552
#define HTTP_FORBIDDEN
Definition httpd.h:511
#define HTTP_NOT_FOUND
Definition httpd.h:512
#define AP_METHOD_BIT
Definition httpd.h:629
#define M_GET
Definition httpd.h:592
#define STANDARD20_MODULE_STUFF
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
@ APR_NOFILE
#define APR_READ
Definition apr_file_io.h:93
#define APR_OS_DEFAULT
#define APR_CUR
apr_vformatter_buff_t * c
Definition apr_lib.h:175
apr_pool_t * b
Definition apr_pools.h:529
Apache Configuration.
Apache Logging library.
Command line options.
HTTP protocol handling.
Apache Request library.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
static int asis_handler(request_rec *r)
Definition mod_asis.c:31
#define ASIS_MAGIC_TYPE
Definition mod_asis.c:29
static void register_hooks(apr_pool_t *p)
Definition mod_asis.c:114
mod_core private header file
return NULL
Definition mod_so.c:359
apr_filetype_e filetype
apr_off_t size
Structure to store things which are per connection.
Definition httpd.h:1152
A structure that represents the current request.
Definition httpd.h:845
int status
Definition httpd.h:891
struct ap_filter_t * output_filters
Definition httpd.h:1070
int header_only
Definition httpd.h:875
const char * handler
Definition httpd.h:994
int method_number
Definition httpd.h:898
apr_pool_t * pool
Definition httpd.h:847
char * filename
Definition httpd.h:1018
conn_rec * connection
Definition httpd.h:849
apr_finfo_t finfo
Definition httpd.h:1094
apr_int64_t allowed
Definition httpd.h:922
const char * method
Definition httpd.h:900
apr_table_t * headers_out
Definition httpd.h:978
Apache script tools.