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
local sock = assert(ngx.req.socket())
local data = assert(sock:peek(1)) -- peek the first 1 byte that contains the length
data = string.byte(data)
data = assert(sock:peek(data + 1)) -- peek the length + the size byte
local payload = data:sub(2) -- trim the length byte to get actual payload
ngx.log(ngx.INFO, "payload is: ", payload)
I'm using Ubuntu 18.04 LTS with Openresty 1.15.8.2-1~bionic1 and I have tried to use the above example with the following configuration:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
}
stream {
resolver 1.1.1.1 ipv6=off valid=1s;
server {
listen 443;
proxy_pass $ssl_preread_server_name.backend.server.local:443;
ssl_preread on;
}
server {
listen 80;
# $the_variable_that_i_want_to_extract = HTTP Host Header taken from request headers
proxy_pass $the_variable_that_i_want_to_extract.backend.server.local:80;
preread_by_lua_block {
local sock = assert(ngx.req.socket())
local data = assert(sock:peek(1))
data = string.byte(data)
ngx.log(ngx.CRIT, "payload is: ", data)
}
}
}
The payload size returned is always 71 even if I make a HTTP request with a very long header "Host: this-is-a-very-long-hostname-which-is-surely-over-71-bytes-long-just-for.example.com". So it seems that your example code will truncate sock:peek length to 71 which is usually not enough to grab all the header data.
What I'm trying to do is to extract HTTP request header data to be able to put HTTP Host Header in to a variable to be able to use it as a part of proxy_pass hostname in a similar way that I can do with HTTPS SSL SNI connections with ngx_stream_ssl_preread_module (http://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html) $ssl_preread_server_name variable.
The text was updated successfully, but these errors were encountered:
Example taken from https://github.com/openresty/stream-lua-nginx-module#reqsockpeek
I'm using Ubuntu 18.04 LTS with Openresty 1.15.8.2-1~bionic1 and I have tried to use the above example with the following configuration:
The payload size returned is always 71 even if I make a HTTP request with a very long header "Host: this-is-a-very-long-hostname-which-is-surely-over-71-bytes-long-just-for.example.com". So it seems that your example code will truncate sock:peek length to 71 which is usually not enough to grab all the header data.
What I'm trying to do is to extract HTTP request header data to be able to put HTTP Host Header in to a variable to be able to use it as a part of proxy_pass hostname in a similar way that I can do with HTTPS SSL SNI connections with ngx_stream_ssl_preread_module (http://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html) $ssl_preread_server_name variable.
The text was updated successfully, but these errors were encountered: