/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* mod_data.c --- Turn the response into an rfc2397 data URL, suitable for
* displaying as inline content on a page.
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_buckets.h"
#include "apr_base64.h"
#include "apr_lib.h"
#include "ap_config.h"
#include "util_filter.h"
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_request.h"
#include "http_protocol.h"
typedef struct data_ctx
{
int count;
} data_ctx;
/**
* Create a data URL as follows:
*
* data:[<mime-type>;][charset=<charset>;]base64,<payload>
*
* Where:
*
* mime-type: The mime type of the original response.
* charset: The optional character set corresponding to the mime type.
* payload: A base64 version of the response body.
*
*
* The Content-Length header, if present, is updated with the new content
* length based on the increase in size expected from the base64 conversion.
* If the Content-Length header is too large to fit into an int, we remove
* the Content-Length header instead.
*/
{
request_rec *r = f->r;
/* first time in? create a context */
if (!ctx) {
char *type;
char *end;
const char *content_length;
/* base64-ing won't work on subrequests, it would be nice if
* it did. Within subrequests, we have no EOS to check for,
* so we don't know when to flush the tail to the network.
*/
if (!ap_is_initial_req(f->r)) {
}
if (type) {
if (charset) {
*charset++ = 0;
if (end) {
*end++ = 0;
}
}
}
if (content_length) {
ap_set_content_length(r, len +
}
else {
}
}
ap_set_content_type(r, "text/plain");
}
/* Do nothing if asked to filter nothing. */
if (APR_BRIGADE_EMPTY(bb)) {
}
const char *data;
/* buffer big enough for 8000 encoded bytes (6000 raw bytes) and terminator */
e = APR_BRIGADE_FIRST(bb);
/* EOS means we are done. */
if (APR_BUCKET_IS_EOS(e)) {
/* write away the tail */
}
/* pass the EOS across */
/* pass what we have down the chain */
/* pass any stray buckets after the EOS down the stack */
}
continue;
}
/* flush what we can, we can't flush the tail until EOS */
if (APR_BUCKET_IS_FLUSH(e)) {
/* pass the flush bucket across */
/* pass what we have down the chain */
continue;
}
/* metadata buckets are preserved as is */
if (APR_BUCKET_IS_METADATA(e)) {
/*
* Remove meta data bucket from old brigade and insert into the
* new.
*/
continue;
}
/* make sure we don't read more than 6000 bytes at a time */
/* size will never be more than 6000 bytes */
APR_BLOCK_READ))) {
/* fill up and write out our overflow buffer if partially used */
size--;
}
}
/* write the main base64 chunk */
if (size) {
}
/* save away any tail in the overflow buffer */
if (tail) {
}
/* pass what we have down the chain */
if (rv) {
/* should break out of the loop, since our write to the client
* failed in some way. */
continue;
}
}
}
return rv;
}
{
}
NULL, /* create per-directory config structure */
NULL, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
data_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};