Skip to content

ngx.location.capture - pass method names #479

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

Closed
wants to merge 4 commits into from

Conversation

aviramc
Copy link

@aviramc aviramc commented Apr 1, 2015

Added the option to pass the method of the subrequests to ngx.location.capture as a string in addition to the integer based value.
This is an update (and a cleaner diff) of pull request #289

…parameter as a string.

If the method string isn't a known Nginx method, it is still passed (and Nginx considers it as unknown).

methods_number = sizeof(ngx_http_lua_ordered_methods) /
sizeof(ngx_http_lua_ordered_methods[0]);
for (method_index = 0; method_index < methods_number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: need a blank line before for loop.

@agentzh
Copy link
Member

agentzh commented Apr 1, 2015

And again, we need some test cases for this new feature in our existing test suite :)

Thank you for your hard work!

@aviramc
Copy link
Author

aviramc commented Apr 9, 2015

@agentzh , made the requested corrections and added test cases

methods_number = sizeof(ngx_http_lua_ordered_methods) /
sizeof(ngx_http_lua_ordered_methods[0]);

for (method_index = 0; method_index < methods_number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm afraid I don't quite like this O(n) operation on such a hot code path. Maybe introduce a hash table here?

Copy link
Contributor

@detailyang detailyang Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agentzh maybe we can do this as the following, i copy this from ngx_http_parse.c:

                switch (p - m) {

                case 3:
                    if (ngx_str3_cmp(m, 'G', 'E', 'T', ' ')) {
                        r->method = NGX_HTTP_GET;
                        break;
                    }

                    if (ngx_str3_cmp(m, 'P', 'U', 'T', ' ')) {
                        r->method = NGX_HTTP_PUT;
                        break;
                    }

                    break;

                case 4:
                    if (m[1] == 'O') {

                        if (ngx_str3Ocmp(m, 'P', 'O', 'S', 'T')) {
                            r->method = NGX_HTTP_POST;
                            break;
                        }

                        if (ngx_str3Ocmp(m, 'C', 'O', 'P', 'Y')) {
                            r->method = NGX_HTTP_COPY;
                            break;
                        }

                        if (ngx_str3Ocmp(m, 'M', 'O', 'V', 'E')) {
                            r->method = NGX_HTTP_MOVE;
                            break;
                        }

                        if (ngx_str3Ocmp(m, 'L', 'O', 'C', 'K')) {
                            r->method = NGX_HTTP_LOCK;
                            break;
                        }

                    } else {

                        if (ngx_str4cmp(m, 'H', 'E', 'A', 'D')) {
                            r->method = NGX_HTTP_HEAD;
                            break;
                        }
                    }

                    break;

                case 5:
                    if (ngx_str5cmp(m, 'M', 'K', 'C', 'O', 'L')) {
                        r->method = NGX_HTTP_MKCOL;
                        break;
                    }

                    if (ngx_str5cmp(m, 'P', 'A', 'T', 'C', 'H')) {
                        r->method = NGX_HTTP_PATCH;
                        break;
                    }

                    if (ngx_str5cmp(m, 'T', 'R', 'A', 'C', 'E')) {
                        r->method = NGX_HTTP_TRACE;
                        break;
                    }

                    break;

                case 6:
                    if (ngx_str6cmp(m, 'D', 'E', 'L', 'E', 'T', 'E')) {
                        r->method = NGX_HTTP_DELETE;
                        break;
                    }

                    if (ngx_str6cmp(m, 'U', 'N', 'L', 'O', 'C', 'K')) {
                        r->method = NGX_HTTP_UNLOCK;
                        break;
                    }

                    break;

                case 7:
                    if (ngx_str7_cmp(m, 'O', 'P', 'T', 'I', 'O', 'N', 'S', ' '))
                    {
                        r->method = NGX_HTTP_OPTIONS;
                    }

                    break;

                case 8:
                    if (ngx_str8cmp(m, 'P', 'R', 'O', 'P', 'F', 'I', 'N', 'D'))
                    {
                        r->method = NGX_HTTP_PROPFIND;
                    }

                    break;

                case 9:
                    if (ngx_str9cmp(m,
                            'P', 'R', 'O', 'P', 'P', 'A', 'T', 'C', 'H'))
                    {
                        r->method = NGX_HTTP_PROPPATCH;
                    }

                    break;
                }

what do you think of it 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@detailyang duplicating this big snippet of code is rather horrifying :) Better be in a separate C function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agentzh yep, i cannot agree more:). we can put this snippet of code as the helper function to ngx_http_lua_util.c. is it okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@detailyang Sounds good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agentzh i will try create a new PR based on this PR to optimizations this code block:)

@agentzh agentzh force-pushed the master branch 2 times, most recently from e7ac10c to cfd4f90 Compare January 31, 2016 19:04
@mingfang
Copy link

mingfang commented Apr 4, 2016

Is this issue still getting merge?

@agentzh
Copy link
Member

agentzh commented Apr 6, 2016

@mingfang Yes. Though needs some cleanup and optimizations.

@lucky-bai
Copy link

@agentzh Is this going to get merged? I would also find this feature really useful.

@agentzh
Copy link
Member

agentzh commented Nov 22, 2016

This PR needs some coding style fixes and should be rebased to the latest master. It's currently having conflicts with the latest master.

@detailyang
Copy link
Contributor

detailyang commented Nov 26, 2016

@agentzh i have rebased to the latest master in #920. And Also do the optimizations which we have talk in the review:)

@mergify
Copy link

mergify bot commented Oct 24, 2021

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Oct 24, 2021
@AndreyPnm
Copy link

Really need this feature

@zhuizhuhaomeng
Copy link
Contributor

Really need this feature

Would you please rebase the code to the latest master?
@detailyang @AndreyPnm

@mergify mergify bot removed the conflict label Mar 20, 2023
@mergify
Copy link

mergify bot commented Mar 20, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Mar 20, 2023
@mergify mergify bot removed the conflict label May 10, 2023
@mergify
Copy link

mergify bot commented May 10, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label May 10, 2023
@mergify mergify bot removed the conflict label Sep 23, 2023
@mergify
Copy link

mergify bot commented Sep 23, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Sep 23, 2023
Copy link

mergify bot commented Mar 6, 2024

This pull request is now in conflict :(

@mergify mergify bot removed the conflict label Feb 13, 2025
Copy link

mergify bot commented Feb 13, 2025

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Feb 13, 2025
@aviramc aviramc closed this Feb 15, 2025
@mergify mergify bot removed the conflict label Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants