apr_status_t modperl_output_filter_handler(ap_filter_t *f, apr_bucket_brigade *bb) { modperl_filter_t *filter; int status; if (((modperl_filter_ctx_t *)f->ctx)->sent_eos) { MP_TRACE_f(MP_FUNC, MP_FILTER_NAME_FORMAT "write_out: EOS was already sent, " "passing through the brigade", MP_FILTER_NAME(f)); return ap_pass_brigade(f->next, bb); } else { filter = modperl_filter_new(f, bb, MP_OUTPUT_FILTER_MODE, 0, 0, 0); status = modperl_run_filter(filter); FILTER_FREE(filter); } switch (status) { case OK: return APR_SUCCESS; case DECLINED: return ap_pass_brigade(f->next, bb); default: return status; /*XXX*/ } }
static apr_status_t apreq_output_filter_test(ap_filter_t *f, apr_bucket_brigade *bb) { request_rec *r = f->r; apreq_handle_t *handle; apr_bucket_brigade *eos; struct ctx_t ctx = {r, bb}; const apr_table_t *t; if (!APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(bb))) return ap_pass_brigade(f->next,bb); eos = apr_brigade_split(bb, APR_BRIGADE_LAST(bb)); handle = apreq_handle_apache2(r); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, r, "appending parsed data"); apr_brigade_puts(bb, NULL, NULL, "\n--APREQ OUTPUT FILTER--\nARGS:\n"); apreq_args(handle, &t); if (t != NULL) apr_table_do(dump_table, &ctx, t, NULL); apreq_body(handle, &t); if (t != NULL) { apr_brigade_puts(bb,NULL,NULL,"BODY:\n"); apr_table_do(dump_table, &ctx, t, NULL); } APR_BRIGADE_CONCAT(bb,eos); return ap_pass_brigade(f->next,bb); }
apr_status_t dav_svn__location_header_filter(ap_filter_t *f, apr_bucket_brigade *bb) { request_rec *r = f->r; const char *master_uri; const char *location, *start_foo = NULL; /* Don't filter if we're in a subrequest or we aren't setup to proxy anything. */ master_uri = dav_svn__get_master_uri(r); master_uri = svn_path_uri_encode(master_uri, r->pool); if (r->main || !master_uri) { ap_remove_output_filter(f); return ap_pass_brigade(f->next, bb); } location = apr_table_get(r->headers_out, "Location"); if (location) { start_foo = ap_strstr_c(location, master_uri); } if (start_foo) { const char *new_uri; start_foo += strlen(master_uri); new_uri = ap_construct_url(r->pool, apr_pstrcat(r->pool, dav_svn__get_root_dir(r), "/", start_foo, SVN_VA_NULL), r); apr_table_set(r->headers_out, "Location", new_uri); } return ap_pass_brigade(f->next, bb); }
static apr_status_t filter_harness(ap_filter_t *f, apr_bucket_brigade *bb) { apr_status_t ret; #ifndef NO_PROTOCOL const char *cachecontrol; char *str; #endif harness_ctx *ctx = f->ctx; ap_filter_rec_t *filter = f->frec; if (f->r->status != 200 && !apr_table_get(f->r->subprocess_env, "filter-errordocs")) { ap_remove_output_filter(f); return ap_pass_brigade(f->next, bb); } filter_trace(f->c, filter->debug, f->frec->name, bb); /* look up a handler function if we haven't already set it */ if (!ctx->func) { #ifndef NO_PROTOCOL if (f->r->proxyreq) { if (filter->proto_flags & AP_FILTER_PROTO_NO_PROXY) { ap_remove_output_filter(f); return ap_pass_brigade(f->next, bb); } if (filter->proto_flags & AP_FILTER_PROTO_TRANSFORM) { cachecontrol = apr_table_get(f->r->headers_out, "Cache-Control"); if (cachecontrol) { str = apr_pstrdup(f->r->pool, cachecontrol); ap_str_tolower(str); if (strstr(str, "no-transform")) { ap_remove_output_filter(f); return ap_pass_brigade(f->next, bb); } } } } #endif if (!filter_lookup(f, filter)) { ap_remove_output_filter(f); return ap_pass_brigade(f->next, bb); } } /* call the content filter with its own context, then restore our * context */ f->ctx = ctx->fctx; ret = ctx->func(f, bb); ctx->fctx = f->ctx; f->ctx = ctx; return ret; }
static apr_status_t ef_output_filter(ap_filter_t *f, apr_bucket_brigade *bb) { request_rec *r = f->r; ef_ctx_t *ctx = f->ctx; apr_status_t rv; if (!ctx) { if ((rv = init_filter_instance(f)) != APR_SUCCESS) { ctx = f->ctx; ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "can't initialise output filter %s: %s", f->frec->name, (ctx->dc->onfail == 1) ? "removing" : "aborting"); ap_remove_output_filter(f); if (ctx->dc->onfail == 1) { return ap_pass_brigade(f->next, bb); } else { apr_bucket *e; f->r->status_line = "500 Internal Server Error"; apr_brigade_cleanup(bb); e = ap_bucket_error_create(HTTP_INTERNAL_SERVER_ERROR, NULL, r->pool, f->c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(bb, e); e = apr_bucket_eos_create(f->c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(bb, e); ap_pass_brigade(f->next, bb); return AP_FILTER_ERROR; } } ctx = f->ctx; } if (ctx->noop) { ap_remove_output_filter(f); return ap_pass_brigade(f->next, bb); } rv = ef_unified_filter(f, bb); if (rv != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "ef_unified_filter() failed"); } if ((rv = ap_pass_brigade(f->next, bb)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "ap_pass_brigade() failed"); } return rv; }
static apr_status_t mod_mruby_output_filter(ap_filter_t* f, apr_bucket_brigade* bb) { apr_status_t rv; request_rec *r = f->r; mruby_dir_config_t *dir_conf = ap_get_module_config(r->per_dir_config, &mruby_module); if (dir_conf->mod_mruby_output_filter_code == NULL) return ap_pass_brigade(f->next, bb); ap_mrb_push_filter(f, bb); rv = ap_mruby_run(ap_mrb_get_mrb_state(r->server->process->pconf), r, dir_conf->mod_mruby_output_filter_code, OK); return ap_pass_brigade(f->next, bb); }
static apr_status_t pass_out(apr_bucket_brigade *bb, void *ctx) { h2_conn_io *io = (h2_conn_io*)ctx; apr_status_t status; apr_off_t bblen; if (APR_BRIGADE_EMPTY(bb)) { return APR_SUCCESS; } ap_update_child_status(io->connection->sbh, SERVER_BUSY_WRITE, NULL); status = apr_brigade_length(bb, 0, &bblen); if (status == APR_SUCCESS) { ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, io->connection, "h2_conn_io(%ld): pass_out brigade %ld bytes", io->connection->id, (long)bblen); status = ap_pass_brigade(io->connection->output_filters, bb); if (status == APR_SUCCESS) { io->bytes_written += (apr_size_t)bblen; io->last_write = apr_time_now(); } apr_brigade_cleanup(bb); } return status; }
static PyObject *filter_flush(filterobject *self, PyObject *args) { conn_rec *c = self->request_obj->request_rec->connection; /* does the output brigade exist? */ if (!self->bb_out) { self->bb_out = apr_brigade_create(self->f->r->pool, c->bucket_alloc); } APR_BRIGADE_INSERT_TAIL(self->bb_out, apr_bucket_flush_create(c->bucket_alloc)); if (!self->is_input) { Py_BEGIN_ALLOW_THREADS; self->rc = ap_pass_brigade(self->f->next, self->bb_out); apr_brigade_destroy(self->bb_out); Py_END_ALLOW_THREADS; if(self->rc != APR_SUCCESS) { PyErr_SetString(PyExc_IOError, "Flush failed."); return NULL; } } Py_INCREF(Py_None); return Py_None; }
/** * This works right now because all timers are invoked in the single listener * thread in the Event MPM -- the same thread that serf callbacks are made * from, so we don't technically need a mutex yet, but with the Simple MPM, * invocations are made from worker threads, and we need to figure out locking */ static void timed_cleanup_callback(void *baton) { s_baton_t *ctx = baton; /* Causes all serf connections to unregister from the event mpm */ if (ctx->rstatus) { ap_log_rerror(APLOG_MARK, APLOG_ERR, ctx->rstatus, ctx->r, APLOGNO(01119) "serf: request returned: %d", ctx->rstatus); ctx->r->status = HTTP_OK; apr_pool_destroy(ctx->serf_pool); ap_die(ctx->rstatus, ctx->r); } else { apr_bucket *e; apr_brigade_cleanup(ctx->tmpbb); e = apr_bucket_flush_create(ctx->r->connection->bucket_alloc); APR_BRIGADE_INSERT_TAIL(ctx->tmpbb, e); e = apr_bucket_eos_create(ctx->r->connection->bucket_alloc); APR_BRIGADE_INSERT_TAIL(ctx->tmpbb, e); /* TODO: return code? bleh */ ap_pass_brigade(ctx->r->output_filters, ctx->tmpbb); apr_pool_destroy(ctx->serf_pool); ap_finalize_request_protocol(ctx->r); ap_process_request_after_handler(ctx->r); return; } }
static apr_status_t flush_out(apr_bucket_brigade *bb, void *ctx) { h2_conn_io *io = (h2_conn_io*)ctx; apr_status_t status = ap_pass_brigade(io->connection->output_filters, bb); apr_brigade_cleanup(bb); return status; }
static ssize_t write_flush(mgs_handle_t * ctxt) { apr_bucket *e; if (!(ctxt->output_blen || ctxt->output_length)) { ctxt->output_rc = APR_SUCCESS; return 1; } if (ctxt->output_blen) { e = apr_bucket_transient_create(ctxt->output_buffer, ctxt->output_blen, ctxt->output_bb-> bucket_alloc); /* we filled this buffer first so add it to the * * head of the brigade * */ APR_BRIGADE_INSERT_HEAD(ctxt->output_bb, e); ctxt->output_blen = 0; } ctxt->output_length = 0; e = apr_bucket_flush_create(ctxt->output_bb->bucket_alloc); APR_BRIGADE_INSERT_TAIL(ctxt->output_bb, e); ctxt->output_rc = ap_pass_brigade(ctxt->output_filter->next, ctxt->output_bb); /* clear the brigade to be ready for next time */ apr_brigade_cleanup(ctxt->output_bb); return (ctxt->output_rc == APR_SUCCESS) ? 1 : -1; }
static PyObject *filter_close(filterobject *self, PyObject *args) { conn_rec *c = self->request_obj->request_rec->connection; if (! self->closed) { /* does the output brigade exist? */ if (!self->bb_out) { self->bb_out = apr_brigade_create(self->f->r->pool, c->bucket_alloc); } APR_BRIGADE_INSERT_TAIL(self->bb_out, apr_bucket_eos_create(c->bucket_alloc)); if (! self->is_input) { Py_BEGIN_ALLOW_THREADS; self->rc = ap_pass_brigade(self->f->next, self->bb_out); apr_brigade_destroy(self->bb_out); Py_END_ALLOW_THREADS; self->bb_out = NULL; } self->closed = 1; } Py_INCREF(Py_None); return Py_None; }
static int php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) { apr_bucket *b; apr_bucket_brigade *bb; apr_bucket_alloc_t *ba; ap_filter_t *f; /* remaining output filters */ php_struct *ctx; ctx = SG(server_context); f = ctx->f; if (str_length == 0) return 0; ba = f->c->bucket_alloc; bb = apr_brigade_create(ctx->r->pool, ba); b = apr_bucket_transient_create(str, str_length, ba); APR_BRIGADE_INSERT_TAIL(bb, b); if (ap_pass_brigade(f->next, bb) != APR_SUCCESS || ctx->r->connection->aborted) { php_handle_aborted_connection(); } return str_length; /* we always consume all the data passed to us. */ }
/** * This is the second most important function, as it delivers the content of the * file (or the directory if not DAV) * @param resource The resource generated previously * @param output Here is where the output must be written * @return NULL on success */ static dav_error *dav_ns_deliver(const dav_resource *resource, ap_filter_t *output) { apr_bucket_brigade *bb; apr_bucket *bkt; dav_error *err; bb = apr_brigade_create(resource->pool, output->c->bucket_alloc); if (resource->collection) err = dav_ns_deliver_collection(resource, resource->info->request->output_filters, bb); else if (resource->info->metalink) { err = dav_ns_deliver_metalink(resource, resource->info->request->output_filters, bb); } else err = dav_new_error(resource->pool, HTTP_INTERNAL_SERVER_ERROR, 0, "NS should not be trying to deliver files!"); if (err != NULL) return err; /* Close and flush the output */ bkt = apr_bucket_eos_create(output->c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(bb, bkt); if (ap_pass_brigade(resource->info->request->output_filters, bb) != APR_SUCCESS) return dav_shared_new_error(resource->info->request, NULL, HTTP_INTERNAL_SERVER_ERROR, "Could not write EOS to filter."); /* All OK */ return NULL; }
/** * Sends a brigade with an error bucket down the filter chain. */ apr_status_t send_error_bucket(modsec_rec *msr, ap_filter_t *f, int status) { apr_bucket_brigade *brigade = NULL; apr_bucket *bucket = NULL; /* Set the status line explicitly for the error document */ f->r->status_line = ap_get_status_line(status); brigade = apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc); if (brigade == NULL) return APR_EGENERAL; bucket = ap_bucket_error_create(status, NULL, f->r->pool, f->r->connection->bucket_alloc); if (bucket == NULL) return APR_EGENERAL; APR_BRIGADE_INSERT_TAIL(brigade, bucket); bucket = apr_bucket_eos_create(f->r->connection->bucket_alloc); if (bucket == NULL) return APR_EGENERAL; APR_BRIGADE_INSERT_TAIL(brigade, bucket); ap_pass_brigade(f->next, brigade); /* NOTE: * It may not matter what we do from the filter as it may be too * late to even generate an error (already sent to client). Nick Kew * recommends to return APR_EGENERAL in hopes that the handler in control * will notice and do The Right Thing. So, that is what we do now. */ return APR_EGENERAL; }
static int cdn_html_filter(ap_filter_t * f, apr_bucket_brigade * bb) { apr_bucket *b; const char *buf = 0; apr_size_t bytes = 0; /* now do HTML filtering if necessary, and pass the brigade onward */ saxctxt *ctxt = check_html_filter_init(f); if (!ctxt) return ap_pass_brigade(f->next, bb); for(b = APR_BRIGADE_FIRST(bb); b != APR_BRIGADE_SENTINEL(bb); b = APR_BUCKET_NEXT(b)) { if(APR_BUCKET_IS_EOS(b) || APR_BUCKET_IS_FLUSH(b)) { consume_buffer(ctxt, buf, 0, 1); APR_BUCKET_REMOVE(b); APR_BRIGADE_INSERT_TAIL(ctxt->bb, b); ap_pass_brigade(ctxt->f->next, ctxt->bb); return APR_SUCCESS; } if(apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ) == APR_SUCCESS && buf) { if(ctxt->parser == NULL) { /* * for now, always output utf-8; we could incorporate * mod_proxy_html's output transcoding with little problem if * necessary */ ap_set_content_type(f->r, "text/html;charset=utf-8"); if(!initialize_parser(f, ctxt, &buf, bytes)) { apr_status_t rv = ap_pass_brigade(ctxt->f->next, bb); ap_remove_output_filter(f); return rv; } else ap_fputs(f->next, ctxt->bb, ctxt->cfg->doctype); } consume_buffer(ctxt, buf, bytes, 0); } } /*ap_fflush(ctxt->f->next, ctxt->bb) ; */ /* uncomment for debug */ apr_brigade_cleanup(bb); return APR_SUCCESS; }
static dav_error * dav_rainx_deliver_SPECIAL(const dav_resource *resource, ap_filter_t *output) { const char *result; int result_len; apr_status_t status; apr_pool_t *pool; apr_bucket_brigade *bb; apr_bucket *bkt; DAV_XDEBUG_RES(resource, 0, "%s()", __FUNCTION__); pool = resource->info->request->pool; /* Check resource type */ if (resource->type != DAV_RESOURCE_TYPE_PRIVATE) return server_create_and_stat_error(resource_get_server_config(resource), pool, HTTP_CONFLICT, 0, apr_pstrdup(pool, "Cannot GET this type of resource.")); if (resource->collection) return server_create_and_stat_error(resource_get_server_config(resource), pool, HTTP_CONFLICT, 0, apr_pstrdup(pool,"No GET on collections")); /* Generate the output */ result = resource->info->generator(resource, pool); result_len = strlen(result); /* We must reply a buffer */ bkt = apr_bucket_heap_create(result, result_len, NULL, output->c->bucket_alloc); bb = apr_brigade_create(pool, output->c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(bb, bkt); /* Nothing more to reply */ bkt = apr_bucket_eos_create(output->c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(bb, bkt); DAV_XDEBUG_RES(resource, 0, "%s : ready to deliver", __FUNCTION__); if ((status = ap_pass_brigade(output, bb)) != APR_SUCCESS) return server_create_and_stat_error(resource_get_server_config(resource), pool, HTTP_FORBIDDEN, 0, apr_pstrdup(pool,"Could not write contents to filter.")); server_inc_stat(resource_get_server_config(resource), RAWX_STATNAME_REP_2XX, 0); /* HERE ADD request counter */ switch(resource->info->type) { case STAT: server_inc_request_stat(resource_get_server_config(resource), RAWX_STATNAME_REQ_STAT, request_get_duration(resource->info->request)); break; case INFO: server_inc_request_stat(resource_get_server_config(resource), RAWX_STATNAME_REQ_INFO, request_get_duration(resource->info->request)); break; default: break; } return NULL; }
// Dump authentication result. static apr_status_t auth_result_dump_filter(ap_filter_t* flt, apr_bucket_brigade* bb) { request_rec* rec = (request_rec*)flt->r; AP_LOG_INFO(rec, "Auth result: user=%s, type=%s", rec->user, rec->ap_auth_type); ap_remove_output_filter(flt); return ap_pass_brigade(flt->next, bb); }
static apr_status_t ap_compile_output_filter(ap_filter_t *filter, apr_bucket_brigade *input_brigade) { request_rec *request = filter->r; if ( ! request->filename) { return ap_pass_brigade(filter->next, input_brigade); } const char *resource_name; compile_config_t *directory_config = (compile_config_t*) ap_get_module_config(request->per_dir_config, &compile_module); compile_config_t *server_config = (compile_config_t*) ap_get_module_config(request->server->module_config, &compile_module); compile_config_t *config = compile_merge_config(request->pool, server_config, directory_config); if (config->use_path_info) { resource_name = apr_pstrcat(request->pool, request->filename, request->path_info, NULL); } else { resource_name = request->filename; } const char *filename; char *extension; filename = ap_strrchr_c(resource_name, '/'); if (filename == NULL) { filename = resource_name; } else { ++ filename; } extension = ap_getword(request->pool, &filename, '.'); while (*filename && (extension = ap_getword(request->pool, &filename, '.'))) { if (*extension == '\0') { continue; } ap_str_tolower(extension); if (config->extension_commands != NULL) { const compile_extension_config_t *extension_config = NULL; extension_config = (compile_extension_config_t*) apr_hash_get(config->extension_commands, extension, APR_HASH_KEY_STRING); if (extension_config != NULL && extension_config->command_line) { #ifdef _DEBUG ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, request->server, "ap_compile_output_filter('%s')", apr_psprintf(request->pool, extension_config->command_line, resource_name)); #endif // TODO: http://svn.apache.org/repos/asf/httpd/httpd/tags/2.2.6/modules/experimental/mod_case_filter.c // Collect buckets, save to disk, run command line and tail-insert result ap_set_content_type(request, "text/html;charset=utf-8"); break; } } } return ap_pass_brigade(filter->next, input_brigade); }
static int process_fortune_connection(conn_rec *c) { apr_status_t rv; apr_procattr_t *pattr; apr_pool_t *p = c->pool; apr_bucket *b; apr_bucket_brigade *bb; const char *err_msg = "200 OK\n"; fortune_conf_t *fconf = ap_get_module_config(c->base_server->module_config, &fortune_module); if (!fconf->enabled) { return DECLINED; } bb = apr_brigade_create(p, c->bucket_alloc); /* prepare process attribute */ if ((rv = apr_procattr_create(&pattr, c->pool)) != APR_SUCCESS) { goto error; } if ((rv = apr_procattr_io_set(pattr, APR_NO_PIPE, APR_FULL_BLOCK, APR_NO_PIPE)) != APR_SUCCESS) { goto error; } /* default value: APR_PROGRAM */ if ((rv = apr_procattr_cmdtype_set(pattr, APR_PROGRAM_ENV)) != APR_SUCCESS) { goto error; } /* run the program and read the output from the pipe */ if ((rv = fortune_process(c, pattr, bb)) != APR_SUCCESS) { apr_brigade_cleanup(bb); } error: if (rv != APR_SUCCESS) { err_msg = "500 ERROR\n"; } b = apr_bucket_pool_create(err_msg, strlen(err_msg), p, c->bucket_alloc); APR_BRIGADE_INSERT_HEAD(bb, b); b = apr_bucket_flush_create(c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(bb, b); rv = ap_pass_brigade(c->output_filters, bb); return OK; }
apr_status_t con_filter(ap_filter_t *f, apr_bucket_brigade *bb) { printf("enter %s %d\n",__FUNCTION__,__LINE__); const char *res; if((res = apr_table_get(f->r->headers_out,"X-Frame-Options"))!=NULL) printf("x-frame-options is %s\n", res); apr_table_setn(f->r->headers_out, "con","i am con"); ap_remove_output_filter(f); return ap_pass_brigade(f->next,bb); }
MP_INLINE static apr_status_t send_output_flush(ap_filter_t *f) { apr_bucket_alloc_t *ba = f->c->bucket_alloc; apr_bucket_brigade *bb = apr_brigade_create(MP_FILTER_POOL(f), ba); apr_bucket *b = apr_bucket_flush_create(ba); APR_BRIGADE_INSERT_TAIL(bb, b); MP_TRACE_f(MP_FUNC, MP_FILTER_NAME_FORMAT "write out: FLUSH bucket in separate bb", MP_FILTER_NAME(f)); return ap_pass_brigade(f, bb); }
MP_INLINE static apr_status_t send_output_eos(ap_filter_t *f) { apr_bucket_alloc_t *ba = f->c->bucket_alloc; apr_bucket_brigade *bb = apr_brigade_create(MP_FILTER_POOL(f), ba); apr_bucket *b = apr_bucket_eos_create(ba); APR_BRIGADE_INSERT_TAIL(bb, b); ((modperl_filter_ctx_t *)f->ctx)->sent_eos = 1; MP_TRACE_f(MP_FUNC, MP_FILTER_NAME_FORMAT "write out: EOS bucket in separate bb", MP_FILTER_NAME(f)); return ap_pass_brigade(f->next, bb); }
static int log_output_start(ap_filter_t *f, apr_bucket_brigade *in){ request_rec *r = f->r; output_start_time = cur_time(); // ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, // "OUTPUT_TIME_S= %f",output_start_time ); ap_remove_output_filter(f); return ap_pass_brigade(f->next, in); }
static apr_status_t send_bucket_downstream(ap_filter_t *f, apr_bucket *b) { charset_filter_ctx_t *ctx = f->ctx; apr_status_t rv; APR_BRIGADE_INSERT_TAIL(ctx->tmpbb, b); rv = ap_pass_brigade(f->next, ctx->tmpbb); if (rv != APR_SUCCESS) { ctx->ees = EES_DOWNSTREAM; } apr_brigade_cleanup(ctx->tmpbb); return rv; }
static apr_status_t send_416(ap_filter_t *f, apr_bucket_brigade *tmpbb) { apr_bucket *e; conn_rec *c = f->r->connection; ap_remove_output_filter(f); f->r->status = HTTP_OK; e = ap_bucket_error_create(HTTP_RANGE_NOT_SATISFIABLE, NULL, f->r->pool, c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(tmpbb, e); e = apr_bucket_eos_create(c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(tmpbb, e); return ap_pass_brigade(f->next, tmpbb); }
static apr_status_t CaseFilterOutFilter(ap_filter_t *f, apr_bucket_brigade *pbbIn) { request_rec *r = f->r; conn_rec *c = r->connection; apr_bucket *pbktIn; apr_bucket_brigade *pbbOut; pbbOut=apr_brigade_create(r->pool, c->bucket_alloc); for (pbktIn = APR_BRIGADE_FIRST(pbbIn); pbktIn != APR_BRIGADE_SENTINEL(pbbIn); pbktIn = APR_BUCKET_NEXT(pbktIn)) { const char *data; apr_size_t len; char *buf; apr_size_t n; apr_bucket *pbktOut; if(APR_BUCKET_IS_EOS(pbktIn)) { apr_bucket *pbktEOS=apr_bucket_eos_create(c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(pbbOut,pbktEOS); continue; } /* read */ apr_bucket_read(pbktIn,&data,&len,APR_BLOCK_READ); /* write */ buf = apr_bucket_alloc(len, c->bucket_alloc); for(n=0 ; n < len ; ++n) buf[n] = apr_toupper(data[n]); pbktOut = apr_bucket_heap_create(buf, len, apr_bucket_free, c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(pbbOut,pbktOut); } /* Q: is there any advantage to passing a brigade for each bucket? * A: obviously, it can cut down server resource consumption, if this * experimental module was fed a file of 4MB, it would be using 8MB for * the 'read' buckets and the 'write' buckets. * * Note it is more efficient to consume (destroy) each bucket as it's * processed above than to do a single cleanup down here. In any case, * don't let our caller pass the same buckets to us, twice; */ apr_brigade_cleanup(pbbIn); return ap_pass_brigade(f->next,pbbOut); }
apr_status_t h2_conn_io_close(h2_conn_io *io, void *session) { apr_bucket *b; /* Send out anything in our buffers */ h2_conn_io_flush_int(io, 0); b = h2_bucket_eoc_create(io->connection->bucket_alloc, session); APR_BRIGADE_INSERT_TAIL(io->output, b); b = apr_bucket_flush_create(io->connection->bucket_alloc); APR_BRIGADE_INSERT_TAIL(io->output, b); return ap_pass_brigade(io->connection->output_filters, io->output); /* and all is gone */ }
static int proxy_wstunnel_transfer(request_rec *r, conn_rec *c_i, conn_rec *c_o, apr_bucket_brigade *bb, char *name) { int rv; #ifdef DEBUGGING apr_off_t len; #endif do { apr_brigade_cleanup(bb); rv = ap_get_brigade(c_i->input_filters, bb, AP_MODE_READBYTES, APR_NONBLOCK_READ, AP_IOBUFSIZE); if (rv == APR_SUCCESS) { if (c_o->aborted) { return APR_EPIPE; } if (APR_BRIGADE_EMPTY(bb)) { break; } #ifdef DEBUGGING len = -1; apr_brigade_length(bb, 0, &len); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02440) "read %" APR_OFF_T_FMT " bytes from %s", len, name); #endif rv = ap_pass_brigade(c_o->output_filters, bb); if (rv == APR_SUCCESS) { ap_fflush(c_o->output_filters, bb); } else { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02441) "error on %s - ap_pass_brigade", name); } } else if (!APR_STATUS_IS_EAGAIN(rv) && !APR_STATUS_IS_EOF(rv)) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(02442) "error on %s - ap_get_brigade", name); } } while (rv == APR_SUCCESS); ap_log_rerror(APLOG_MARK, APLOG_TRACE2, rv, r, "wstunnel_transfer complete"); if (APR_STATUS_IS_EAGAIN(rv)) { rv = APR_SUCCESS; } return rv; }
// Filter outgoing content of requests and replace `Set-Cookie` headers by a // single token (defined in input handler). // The upstream cookies will be stored through the configured driver. apr_status_t psm_output_filter(ap_filter_t* f, apr_bucket_brigade* bb) { psm_request_vars *vars; psm_filter_data *data; psm_server_conf *conf; // Fetch configuration of the server conf = (psm_server_conf*) ap_get_module_config(f->r->server->module_config, &psm_module); // Execute filter only on initial request if (! ap_is_initial_req(f->r)) return ap_pass_brigade(f->next, bb); // Fetch configuration created by `psm_input_handler` vars = (psm_request_vars *)ap_get_module_config(f->r->request_config, &psm_module); if (vars == NULL) { // TODO GENERATE ERROR: 500 } // Parse and list every 'Set-Cookie' headers data = (psm_filter_data *)apr_palloc(f->r->pool, sizeof(psm_filter_data)); data->request = f->r; data->cookies = apr_array_make(f->r->pool, PSM_ARRAY_INIT_SZ, sizeof(psm_cookie *)); apr_table_do(psm_parse_set_cookie, data, f->r->headers_out, HEADER_SET_COOKIE, NULL); // Let the driver save cookies conf->driver->save_cookies(f->r->pool, *conf->driver->data, data->cookies, vars->token); // Replace outgoing "Set-Cookie" header by session token psm_write_set_cookie(f->r->headers_out, &(psm_cookie) { PSM_TOKEN_NAME, vars->token, }); // Remove this filter and go to next one ap_remove_output_filter(f); return ap_pass_brigade(f->next, bb); }