78
88
if (len == sizeof("headers_sent") - 1
79
89
&& ngx_strncmp(p, "headers_sent", sizeof("headers_sent") - 1) == 0)
81
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
83
return luaL_error(L, "no ctx");
86
ngx_http_lua_check_fake_request2(L, r, ctx);
88
dd("headers sent: %d", ctx->headers_sent);
90
lua_pushboolean(L, ctx->headers_sent ? 1 : 0);
91
ngx_http_lua_check_fake_request(L, r);
93
dd("headers sent: %d", r->header_sent);
95
lua_pushboolean(L, r->header_sent ? 1 : 0);
121
116
if (len == sizeof("status") - 1
122
117
&& ngx_strncmp(p, "status", sizeof("status") - 1) == 0)
124
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
119
r = ngx_http_lua_get_req(L);
121
return luaL_error(L, "no request object found");
126
if (ctx->headers_sent) {
124
if (r->header_sent) {
127
125
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
128
126
"attempt to set ngx.status after sending out "
129
127
"response headers");
133
ngx_http_lua_check_fake_request2(L, r, ctx);
131
ngx_http_lua_check_fake_request(L, r);
135
133
/* get the value */
136
134
r->headers_out.status = (ngx_uint_t) luaL_checknumber(L, 3);
136
if (r->headers_out.status == 101) {
138
* XXX work-around a bug in the Nginx core that 101 does
139
* not have a default status line
142
ngx_str_set(&r->headers_out.status_line, "101 Switching Protocols");
145
r->headers_out.status_line.len = 0;
151
if (len == sizeof("ctx") - 1
152
&& ngx_strncmp(p, "ctx", sizeof("ctx") - 1) == 0)
154
r = ngx_http_lua_get_req(L);
156
return luaL_error(L, "no request object found");
159
return ngx_http_lua_ngx_set_ctx(L);
167
#ifndef NGX_HTTP_LUA_NO_FFI_API
169
ngx_http_lua_ffi_get_resp_status(ngx_http_request_t *r)
171
if (r->connection->fd == -1) {
172
return NGX_HTTP_LUA_FFI_BAD_CONTEXT;
176
return r->err_status;
178
} else if (r->headers_out.status) {
179
return r->headers_out.status;
181
} else if (r->http_version == NGX_HTTP_VERSION_9) {
191
ngx_http_lua_ffi_set_resp_status(ngx_http_request_t *r, int status)
193
if (r->connection->fd == -1) {
194
return NGX_HTTP_LUA_FFI_BAD_CONTEXT;
197
if (r->header_sent) {
198
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
199
"attempt to set ngx.status after sending out "
204
r->headers_out.status = status;
208
* XXX work-around a bug in the Nginx core older than 1.5.5
209
* that 101 does not have a default status line
212
ngx_str_set(&r->headers_out.status_line, "101 Switching Protocols");
137
215
r->headers_out.status_line.len = 0;
141
if (len == sizeof("ctx") - 1
142
&& ngx_strncmp(p, "ctx", sizeof("ctx") - 1) == 0)
144
return ngx_http_lua_ngx_set_ctx(L);
147
return luaL_error(L, "attempt to write to ngx. with the key \"%s\"", p);
223
ngx_http_lua_ffi_is_subrequest(ngx_http_request_t *r)
225
if (r->connection->fd == -1) {
226
return NGX_HTTP_LUA_FFI_BAD_CONTEXT;
234
ngx_http_lua_ffi_headers_sent(ngx_http_request_t *r)
236
ngx_http_lua_ctx_t *ctx;
238
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
240
return NGX_HTTP_LUA_FFI_NO_REQ_CTX;
243
if (r->connection->fd == -1) {
244
return NGX_HTTP_LUA_FFI_BAD_CONTEXT;
247
return r->header_sent ? 1 : 0;
249
#endif /* NGX_HTTP_LUA_NO_FFI_API */
150
252
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */