You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.markdown
+37
Original file line number
Diff line number
Diff line change
@@ -4147,6 +4147,25 @@ to be returned when reading `ngx.header.Foo`.
4147
4147
4148
4148
Note that `ngx.header` is not a normal Lua table and as such, it is not possible to iterate through it using the Lua `ipairs` function.
4149
4149
4150
+
Note: if the current response does not have a Content-Type header, but you use
4151
+
`ngx.header` to attempt retrieving it, a side effect will be that a
4152
+
Content-Type header will be created and returned according to your nginx
4153
+
configuration.
4154
+
4155
+
For example:
4156
+
4157
+
```nginx
4158
+
4159
+
location = /t {
4160
+
default_type text/html;
4161
+
content_by_lua_block {
4162
+
-- even if the response had no Content-Type header,
4163
+
-- it will now have: Content-Type: text/html
4164
+
ngx.say(ngx.header['Content-Type'])
4165
+
}
4166
+
}
4167
+
```
4168
+
4150
4169
For reading *request* headers, use the [ngx.req.get_headers](#ngxreqget_headers) function instead.
4151
4170
4152
4171
[Back to TOC](#nginx-api-for-lua)
@@ -4172,6 +4191,24 @@ Returns a Lua table holding all the current response headers for the current req
4172
4191
end
4173
4192
```
4174
4193
4194
+
Note: if the current response does not have a Content-Type header, but you use
4195
+
`ngx.resp.get_headers` to attempt retrieving it, a side effect will
4196
+
be that a Content-Type header will be created and returned according to your
4197
+
nginx configuration.
4198
+
4199
+
For example:
4200
+
4201
+
```nginx
4202
+
4203
+
location = /t {
4204
+
default_type text/html;
4205
+
content_by_lua_block {
4206
+
-- the Content-Type header will be text/html
4207
+
ngx.say(ngx.resp.get_headers()['Content-Type'])
4208
+
}
4209
+
}
4210
+
```
4211
+
4175
4212
This function has the same signature as [ngx.req.get_headers](#ngxreqget_headers) except getting response headers instead of request headers.
4176
4213
4177
4214
Note that a maximum of 100 response headers are parsed by default (including those with the same name) and that additional response headers are silently discarded to guard against potential denial of service attacks. Since `v0.10.13`, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
Copy file name to clipboardExpand all lines: doc/HttpLuaModule.wiki
+35
Original file line number
Diff line number
Diff line change
@@ -3433,6 +3433,24 @@ to be returned when reading <code>ngx.header.Foo</code>.
3433
3433
3434
3434
Note that <code>ngx.header</code> is not a normal Lua table and as such, it is not possible to iterate through it using the Lua <code>ipairs</code> function.
3435
3435
3436
+
Note: if the current response does not have a Content-Type header, but you use
3437
+
<code>ngx.header</code> to attempt retrieving it, a side effect will be that a
3438
+
Content-Type header will be created and returned according to your nginx
3439
+
configuration.
3440
+
3441
+
For example:
3442
+
3443
+
<geshi lang="nginx">
3444
+
location = /t {
3445
+
default_type text/html;
3446
+
content_by_lua_block {
3447
+
-- even if the response had no Content-Type header,
3448
+
-- it will now have: Content-Type: text/html
3449
+
ngx.say(ngx.header['Content-Type'])
3450
+
}
3451
+
}
3452
+
</geshi>
3453
+
3436
3454
For reading ''request'' headers, use the [[#ngx.req.get_headers|ngx.req.get_headers]] function instead.
3437
3455
3438
3456
== ngx.resp.get_headers ==
@@ -3454,6 +3472,23 @@ for k, v in pairs(h) do
3454
3472
end
3455
3473
</geshi>
3456
3474
3475
+
Note: if the current response does not have a Content-Type header, but you use
3476
+
<code>ngx.resp.get_headers</code>, a side effect will be that a Content-Type
3477
+
header will be created and returned according to your nginx configuration.
3478
+
3479
+
For example:
3480
+
3481
+
<geshi lang="nginx">
3482
+
location = /t {
3483
+
default_type text/html;
3484
+
content_by_lua_block {
3485
+
-- even if the response had no Content-Type header,
3486
+
-- it will now have: Content-Type: text/html
3487
+
ngx.say(ngx.resp.get_headers()['Content-Type'])
3488
+
}
3489
+
}
3490
+
</geshi>
3491
+
3457
3492
This function has the same signature as [[#ngx.req.get_headers|ngx.req.get_headers]] except getting response headers instead of request headers.
3458
3493
3459
3494
Note that a maximum of 100 response headers are parsed by default (including those with the same name) and that additional response headers are silently discarded to guard against potential denial of service attacks. Since <code>v0.10.13</code>, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
0 commit comments