Skip to content

A 3rd party module to handle request body filter on runtime before proxy to backend. It's good if filter certain content and redirect to other path

License

Notifications You must be signed in to change notification settings

Taymindis/nginx-if-request-body

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

nginx-if-request-body

For body filter before proxy to backend

Example:

http {
  ....
    
    map "$uri" $forward_status {
        default 100; # 100 means nothing return, continue to proxy phase
        "~*.+?\.(css|js|bmp|gif|ico|jpeg|jpg|pict|png|svg|swf|tif)$" 418;
    }
   map "$request_body" $forward_status_by_body {
        default 100;
        "abc123xxx" 418;
        "~*.+?\.(css|js|bmp|gif|ico|jpeg|jpg|pict|png|svg|swf|tif)$" 418;
    }

  server {
   ...
        error_page 418 =200 @welcome_if_request_body;
        error_page 419 =200 @proxy_via_if_request_body;
        
         location @proxy_via_if_request_body {
           proxy_pass http://$http_forward_proxy;
        }
        
        location @welcome_if_request_body {
            add_header Content-Type text/plain;
            return 200 "welcome_if_request_body, you hit it";
        }

        location = / {
            if_request_body on;
            return_status_if_body_eq "ASD" 418 on;
            return_status_if_body_eq "foo" 418;
            return_status_if_body_eq "john" 418;
            return_status_if_body_startswith "report" 418;
            return_status_if_body_contains "report" 418;
            return_status_if_body_regex "^[\d]+?abc" 418;
            return_status_if_body_regex "^vendor_api.*" 419;
            return_status_if_variable_map_to $forward_status;
            return_status_if_variable_map_to $forward_status_by_body;
            add_header_in_if_matched "forward-proxy" $upstream_name;
            proxy_pass http://localhost:7777;

        }
...
    }
}

About

A 3rd party module to handle request body filter on runtime before proxy to backend. It's good if filter certain content and redirect to other path

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages