Skip to content

Pass same request method as original to sub-request made by ngx.location.capture #536

@ram-nadella

Description

@ram-nadella

Hey Mr. agentzh,

It's Ram, your old co-worker :)

Been playing around with nginx lua more these days. I am trying to do something with the power of nginx lua and mofo Sikora's aka @PiotrSikora :P cache purge module.

I've got it compiled by downloading source and adding cache purge repo to bundle folder and editing the configure script. I have a content_by_lua_file setup and in my lua code I am able to make a sub-request and when making the sub-request, I want to pass the same request method as the original request.

It appears that the method key in the options passed to ngx.location.capture expects one of the constants (eg. ngx.HTTP_GET) where as both ngx.var.request_method and ngx.req.get_method both return the request method string (GET).

Is there any way to auto-map the request method without doing a switch statement and compare the strings?

(Also, I am not seeing all the headers I expect in the sub-request. I see them all when I hit the location directly using curl but when I do a sub-request using local res = ngx.location.capture(...) and print headers by iterating over res.header I don't see them all)

Edit: ignore the part about the missing headers. That was my bad, I was not passing the args from the original request to the sub-request and the header I was expecting is only returned when those particular args are present. oops.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions