-
Notifications
You must be signed in to change notification settings - Fork 233
Add headers if not set #65
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
Open
detailyang
wants to merge
27
commits into
openresty:master
Choose a base branch
from
detailyang: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
27 commits
Select commit
Hold shift + click to select a range
d48ca6a
add objs/* and autoconf to gitignore
detailyang 4b5f079
add -i option (if not set) to more_set_input_headers
detailyang 8344531
add -i option (if not set) to more_set_headers
detailyang 3b64ac7
allow if no set on non builtin header on more_set_headers
detailyang 6d45d4f
add test for -i option
detailyang 5c73081
better prompt when skip with -i option
detailyang c802c27
add -i option description to README
detailyang 48c4d43
if no set should work on multi header
detailyang 12c3a00
work together on -r replace and -i if not set
detailyang 30daad1
add test for -i (if not set) option
detailyang 9c53270
Fix: do not set header when header already set
detailyang ec1fad6
add test for -r -t -i
detailyang ac52358
add test for more_set_headers on -i -t work together
detailyang b073439
Merge branch 'master' of https://github.com/detailyang/headers-more-n…
detailyang e9fbadf
remove misc in gitignore because of we are using the standard building
detailyang e4202d1
reindex t/*.t
detailyang 0a6073d
correct code style
detailyang fe4f575
typo: grammer fix
detailyang 0c93a4c
add new line in gitignore
detailyang c987b90
remove Makefile new line in gitignore
detailyang df0e156
trailing line space
detailyang 5a0a562
typo -i to -a at t/sanity.t
detailyang cdfc604
boolean equal shoule use ! rather than 0
detailyang 15ae885
Ditto, Boolean field test should use the !a instead of the a == 0
detailyang 34c5f33
typo: doesnt => do not
detailyang bb8a365
typo it do not => it does not
detailyang 964d53c
typo remove new values on README.markdown
detailyang 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -224,6 +224,12 @@ ngx_http_set_header_helper(ngx_http_request_t *r, | |
|
|
||
| matched: | ||
|
|
||
| if (hv->add_only) { | ||
| dd("skip because %s does set", hv->key.data); | ||
| matched = 1; | ||
| continue; | ||
| } | ||
|
|
||
| if (value->len == 0 || matched) { | ||
| dd("clearing normal header for %.*s", (int) hv->key.len, | ||
| hv->key.data); | ||
|
|
@@ -304,6 +310,11 @@ ngx_http_set_builtin_header(ngx_http_request_t *r, | |
| return ngx_http_set_header_helper(r, hv, value, old, 0); | ||
| } | ||
|
|
||
| if (hv->add_only) { | ||
| dd("skip because %s does set", hv->key.data); | ||
| return NGX_OK; | ||
| } | ||
|
|
||
| h = *old; | ||
|
|
||
| if (value->len == 0) { | ||
|
|
@@ -344,6 +355,11 @@ ngx_http_set_builtin_multi_header(ngx_http_request_t *r, | |
| /* override old values (if any) */ | ||
|
|
||
| if (pa->nelts > 0) { | ||
| if (hv->add_only) { | ||
| dd("skip because %s does set", hv->key.data); | ||
| return NGX_OK; | ||
| } | ||
|
|
||
| ph = pa->elts; | ||
| for (i = 1; i < pa->nelts; i++) { | ||
| ph[i]->hash = 0; | ||
|
|
@@ -565,16 +581,17 @@ static char * | |
| ngx_http_headers_more_parse_directive(ngx_conf_t *cf, ngx_command_t *ngx_cmd, | ||
| void *conf, ngx_http_headers_more_opcode_t opcode) | ||
| { | ||
| ngx_flag_t add_only = 0; | ||
| ngx_http_headers_more_loc_conf_t *hlcf = conf; | ||
|
|
||
| ngx_uint_t i; | ||
| ngx_http_headers_more_cmd_t *cmd; | ||
| ngx_str_t *arg; | ||
| ngx_flag_t ignore_next_arg; | ||
| ngx_str_t *cmd_name; | ||
| ngx_int_t rc; | ||
|
|
||
| ngx_http_headers_more_main_conf_t *hmcf; | ||
| ngx_str_t *arg; | ||
| ngx_str_t *cmd_name; | ||
| ngx_int_t rc; | ||
| ngx_flag_t ignore_next_arg; | ||
| ngx_uint_t i; | ||
| ngx_http_headers_more_cmd_t *cmd; | ||
| ngx_http_headers_more_main_conf_t *hmcf; | ||
| ngx_http_headers_more_header_val_t *h; | ||
|
|
||
| if (hlcf->cmds == NULL) { | ||
| hlcf->cmds = ngx_array_create(cf->pool, 1, | ||
|
|
@@ -680,6 +697,10 @@ ngx_http_headers_more_parse_directive(ngx_conf_t *cf, ngx_command_t *ngx_cmd, | |
| ignore_next_arg = 1; | ||
|
|
||
| continue; | ||
|
|
||
| } else if (arg[i].data[1] == 'a') { | ||
| add_only = 1; | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -695,6 +716,13 @@ ngx_http_headers_more_parse_directive(ngx_conf_t *cf, ngx_command_t *ngx_cmd, | |
|
|
||
| if (cmd->headers->nelts == 0) { | ||
| cmd->headers = NULL; | ||
|
|
||
| } else { | ||
| h = cmd->headers->elts; | ||
|
|
||
| for (i = 0; i < cmd->headers->nelts; i++) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need a blank line before the |
||
| h[i].add_only = add_only; | ||
| } | ||
| } | ||
|
|
||
| if (cmd->types->nelts == 0) { | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
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.
Ditto.