4

Is there a way i can apply string replace on a nginx variable. I am using nginx as a proxy for s3 restricted downloads. And i am forwarding the $upstream_http_etag to the response header with the different name.

add_header Content-MD5 $upstream_http_etag;
proxy_set_header Content-MD5 $upstream_http_etag;

The problem is etag is double quoted. I wanted to remove this double quotes before adding it to the header. Is there a possible way to do this.

I know i can strip it down on the client. But this is for older apps to work without the updates.

Any help is much appreciated.

1 Answer 1

1

One possible solution is use header_filter_by_lua directive of lua-nginx-module instead of add_header directive.

For example,

location / {
    header_filter_by_lua '
            -- delete double quoted
            local value = string.gsub(ngx.var.upstream_http_etag or "", [[^"(.+)"$]], "%1")
            -- add response header
            ngx.header["Content-MD5"] = value
    ';
    proxy_pass ...;
}

BTW, proxy_set_header is used to pass extra request header to upstream, however, $upstream_http_etag is upstream response header.
So proxy_set_header Content-MD5 $upstream_http_etag; makes no sense.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.