Coder Social home page Coder Social logo

alter-cash / nginx-if-request-body Goto Github PK

View Code? Open in Web Editor NEW

This project forked from taymindis/nginx-if-request-body

0.0 0.0 0.0 37 KB

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: Other

C 100.00%

nginx-if-request-body's Introduction

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;

        }
...
    }
}

nginx-if-request-body's People

Contributors

taymindis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.