-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add request (input) header for output handler #40
Open
jtfrey
wants to merge
4
commits into
nmaier:master
Choose a base branch
from
jtfrey:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0a07810
Add a request header to indicate when the mod_xsendfile filter is act…
jtfrey 4eefe20
Minor fixup to return values in ap_xsendfile_add_request_header()
jtfrey bb915b5
Removed unused variable, sr, from ap_xsendfile_output_filter()
jtfrey 6672a2b
- Value of X-SENDFILE-IS-ENABLED header changed to be a user-agent-li…
jtfrey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
* Nils Maier <[email protected]> | ||
* Ben Timby - URL decoding | ||
* Jake Rhee - X-SENDFILE-TEMPORARY | ||
* Jeff Frey - X-SENDFILE-IS-ENABLED request header addition | ||
****/ | ||
|
||
/**** | ||
|
@@ -34,6 +35,7 @@ | |
****/ | ||
|
||
/* Version: 1.0 */ | ||
#define AP_XSENDFILE_VERSION "1.0" | ||
|
||
#include "apr.h" | ||
#include "apr_lib.h" | ||
|
@@ -59,6 +61,11 @@ | |
#define AP_XSENDFILE_HEADER "X-SENDFILE" | ||
#define AP_XSENDFILETEMPORARY_HEADER "X-SENDFILE-TEMPORARY" | ||
|
||
#define AP_XSENDFILE_IS_ENABLED_HEADER "X-SENDFILE-IS-ENABLED" | ||
#ifndef AP_XSENDFILE_IS_ENABLED_HEADER_VALUE | ||
#define AP_XSENDFILE_IS_ENABLED_HEADER_VALUE "mod_xsendfile/" AP_XSENDFILE_VERSION | ||
#endif | ||
|
||
module AP_MODULE_DECLARE_DATA xsendfile_module; | ||
|
||
typedef enum { | ||
|
@@ -292,8 +299,23 @@ static apr_status_t ap_xsendfile_get_filepath(request_rec *r, | |
return rv; | ||
} | ||
|
||
static xsendfile_conf_active_t ap_xsendfile_enabled_for_request(request_rec *r) { | ||
xsendfile_conf_active_t enabled = ((xsendfile_conf_t *)ap_get_module_config(r->per_dir_config, &xsendfile_module))->enabled; | ||
if (XSENDFILE_UNSET == enabled) { | ||
enabled = ((xsendfile_conf_t*)ap_get_module_config(r->server->module_config, &xsendfile_module))->enabled; | ||
} | ||
return enabled; | ||
} | ||
|
||
static int ap_xsendfile_add_request_header(request_rec *r) { | ||
if (XSENDFILE_ENABLED == ap_xsendfile_enabled_for_request(r)) { | ||
apr_table_setn(r->headers_in, AP_XSENDFILE_IS_ENABLED_HEADER, AP_XSENDFILE_IS_ENABLED_HEADER_VALUE); | ||
} | ||
return OK; | ||
} | ||
|
||
static apr_status_t ap_xsendfile_output_filter(ap_filter_t *f, apr_bucket_brigade *in) { | ||
request_rec *r = f->r, *sr = NULL; | ||
request_rec *r = f->r; | ||
|
||
xsendfile_conf_t | ||
*dconf = ap_get_module_config(r->per_dir_config, &xsendfile_module), | ||
|
@@ -631,12 +653,7 @@ static apr_status_t ap_xsendfile_output_filter(ap_filter_t *f, apr_bucket_brigad | |
} | ||
|
||
static void ap_xsendfile_insert_output_filter(request_rec *r) { | ||
xsendfile_conf_active_t enabled = ((xsendfile_conf_t *)ap_get_module_config(r->per_dir_config, &xsendfile_module))->enabled; | ||
if (XSENDFILE_UNSET == enabled) { | ||
enabled = ((xsendfile_conf_t*)ap_get_module_config(r->server->module_config, &xsendfile_module))->enabled; | ||
} | ||
|
||
if (XSENDFILE_ENABLED != enabled) { | ||
if (XSENDFILE_ENABLED != ap_xsendfile_enabled_for_request(r)) { | ||
return; | ||
} | ||
|
||
|
@@ -693,6 +710,13 @@ static void xsendfile_register_hooks(apr_pool_t *p) { | |
AP_FTYPE_CONTENT_SET | ||
); | ||
|
||
ap_hook_fixups( | ||
ap_xsendfile_add_request_header, | ||
NULL, | ||
NULL, | ||
APR_HOOK_LAST | ||
); | ||
|
||
ap_hook_insert_filter( | ||
ap_xsendfile_insert_output_filter, | ||
NULL, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is duplicated code, add some function like
ap_xsendfile_enabled_for(request_rec*)
and use it in all places.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented ap_xsendfile_enabled_for_request()