A
A
acc4all2020-10-14 14:09:35
Nginx
acc4all, 2020-10-14 14:09:35

nginx proxy. Is it possible to extract the 'Content-Type' headers of a response?

You need to get the value of 'Content-Type'. Is it possible to extract the headers from the proxied response using nginx? By analogy with the $content_type of the request. For example,

server {
  listen 8080;
  location / {
    proxy_pass https://example.com;

    ...
    # извлечение 'Content-Type'
    ...

    if ($extracted_content_type ~* "text/html") {
      ...
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Shalganov, 2020-10-14
@acc4all

In fact, when proxy_pass is launched, nothing will stop NGINX from proxying and, as a result, it is hard to read what it has proxied there. Nevertheless, it is possible, but with reservations.
If you need to go straight ahead and catch Content-Type, then you will have to customize nginx. or rather, embed the ngx_lua module (necessarily based on luajit) in the world is referred to as OpenResty (there are ready-made nginx + lua assemblies).
After that, you can add the header_filter_by_lua_block directive, which will allow you to catch and change the proxied headers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question