-
Notifications
You must be signed in to change notification settings - Fork 275
feature: add the balancer.recreate_request
function, which allows user to recreate request buffer in balancer phase.
#302
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
Conversation
@dndx just a reminder, the CI failed. |
ef551a4
to
20204f1
Compare
@doujiang24 Yes the test plan was wrong. I have fixed the number. |
20204f1
to
5a27cf2
Compare
…ocao These will be removed once openresty/lua-nginx-module#1734 and openresty/lua-resty-core#302 are merged
…ocao These will be removed once openresty/lua-nginx-module#1734 and openresty/lua-resty-core#302 are merged
Ping @doujiang24. Could you give another look at this? Thanks! |
lib/ngx/balancer.lua
Outdated
@@ -38,6 +38,10 @@ if subsystem == 'http' then | |||
int ngx_http_lua_ffi_balancer_set_timeouts(ngx_http_request_t *r, | |||
long connect_timeout, long send_timeout, | |||
long read_timeout, char **err); | |||
|
|||
int | |||
ngx_http_lua_ffi_balancer_recreate_request(ngx_http_request_t *r, |
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.
style: FFI prototype declarations should have the return type on the same line, like in the C module
lib/ngx/balancer.md
Outdated
@@ -237,6 +237,29 @@ This function was first added in the `0.1.7` version of this library. | |||
|
|||
[Back to TOC](#table-of-contents) | |||
|
|||
recreate_request | |||
------------ |
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.
style: this line should underline the whole method name
lib/ngx/balancer.md
Outdated
|
||
**context:** *balancer_by_lua** | ||
|
||
Regenerates the request buffer for sending to the upstream server. This is useful, for example |
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.
Maybe better to stay consistent with wording? i.e. use "recreate" instead of "regenerate" which is the terminology used everywhere else when referring to this API.
lib/ngx/balancer.md
Outdated
|
||
Normally this does not work because the request buffer is created once during upstream module | ||
initialization and won't be regenerated for subsequent retries. However you can use | ||
`proxy_set_header My-Header $my_header` and sets the `ngx.var.my_header` variable inside the |
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.
s/sets/set/
lib/ngx/balancer.md
Outdated
Normally this does not work because the request buffer is created once during upstream module | ||
initialization and won't be regenerated for subsequent retries. However you can use | ||
`proxy_set_header My-Header $my_header` and sets the `ngx.var.my_header` variable inside the | ||
balancer phase. Calling this function after that will cause the request buffer to be re-generated |
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.
"Calling this function after that" can be confusing for the reader. "Calling balancer.recreate_request()
after updating a header field will cause..."
lib/ngx/balancer.md
Outdated
and the `My-Header` header will thus contain the new value. | ||
|
||
**Warning:** because the request buffer has to be recreated and such allocation occurs on the | ||
request memory pool, the old buffer has to be thrown away and only be freed after the request |
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.
and will only be freed when...
to recreate request buffer in balancer phase. This allows certain request parameters, such as headers (including `Host` header) to be modified between balancer retries.
5a27cf2
to
1e749c8
Compare
Thanks for the reviews @thibaultcha, I fixed the styling and ran the document through with |
lib/ngx/balancer.md
Outdated
to this function should be made **only** if you know the request buffer must be regenerated, | ||
instead of unconditionally in each balancer retries. | ||
|
||
This function was first added in the `0.1.19` version of this library. |
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 should be changed to 0.1.20
.
t/balancer.t
Outdated
print("here") | ||
local b = require "ngx.balancer" | ||
|
||
if ngx.ctx.balancer_ran then |
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.
I think balancer_run
is more grammatically correct.
…ser to recreate request buffer in balancer phase. (#302) This allows certain request parameters, such as headers (including `Host` header) to be modified between balancer retries.
I hereby granted the copyright of the changes in this pull request
to the authors of this lua-resty-core project.
Feature was originally developed by @locao inside Kong/lua-kong-nginx-module#13. With slight modifications from @dndx.
Related PR: openresty/lua-nginx-module#1734.