Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/ngx/resp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local FFI_BAD_CONTEXT = base.FFI_BAD_CONTEXT
local core_response = require "resty.core.response"
local set_resp_header = core_response.set_resp_header
local get_request = base.get_request
local bypass_if_checks = core_response.bypass_if_checks

ffi.cdef[[
int ngx_http_lua_ffi_set_resp_status_and_reason(ngx_http_request_t *r,
Expand Down Expand Up @@ -43,4 +44,9 @@ function _M.set_status(status, reason)
end
end


function _M.bypass_if_checks()
return bypass_if_checks()
end

return _M
18 changes: 18 additions & 0 deletions lib/ngx/resp.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Table of Contents
* [Methods](#methods)
* [add_header](#add_header)
* [set_status](#set_status)
* [bypass_if_checks](#bypass_if_checks)
* [Community](#community)
* [English Mailing List](#english-mailing-list)
* [Chinese Mailing List](#chinese-mailing-list)
Expand Down Expand Up @@ -87,6 +88,23 @@ status with an optional reason. The `reason` should be a string.

[Back to TOC](#table-of-contents)

bypass_if_checks
------------------
**syntax:** *ngx_resp.bypass_if_checks()*

Bypasses the conditional header checks as defined in RFC 9110 for the current request.
This method is useful when you need to skip validation of headers such as `If-Modified-Since`,
`If-None-Match`, `If-Range`, `If-Unmodified-Since`, and `If-Match`, allowing the response to
proceed without evaluating these conditions.
Copy link
Member

Choose a reason for hiding this comment

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

What about also writing down the Why? When people have to call this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add desc


When Nginx's validation of a conditional request fails, it has a specific response.
It will return a 412 error, as per the provisions of Section 13 of RFC 9110. If `error_page 412` is configured,
it will result in an internal redirect to the error handling process, making it impossible to customize the exit status code.

This configuration, designed to bypass Nginx's built-in validation of conditional requests, serves a specific purpose.

[Back to TOC](#table-of-contents)

Community
=========

Expand Down
14 changes: 14 additions & 0 deletions lib/resty/core/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ ffi.cdef[[
const unsigned char *key, size_t key_len,
unsigned char *key_buf, ngx_http_lua_ffi_str_t *values,
int max_nvalues, char **errmsg);

int ngx_http_lua_ffi_bypass_if_checks(ngx_http_request_t *r);
]]


Expand Down Expand Up @@ -226,6 +228,18 @@ local function get_resp_header(tb, key)
end


local function bypass_if_checks()
local r = get_request()
if not r then
error("no request found")
end
C.ngx_http_lua_ffi_bypass_if_checks(r)
end


_M.bypass_if_checks = bypass_if_checks


do
local mt = new_tab(0, 2)
mt.__newindex = set_resp_header
Expand Down