Giter Site home page Giter Site logo

http-header-modify-route-tagger's Introduction

Add HTTP header based on client Remote address

In a scenario we needed to add a custom http header to client http-request based on his IP address.

NGINX

This can be accomplished in two ways: the short and easily accessible approach is spine up a NGINX server with config (proxy.conf) you may find in the nginx directory. For more ease, you can run this command to run the new container for this propose.

You can find another config (default.conf) in the nginx directory which has a custom logging activated which will add this new custom HTTP header (route-tag) to the logs. I used this config for testing the scenario.

docker run -it -v  proxy.conf:/etc/nginx/conf.d/default.conf --rm -d -p 8081:80 --name proxy nginx

default.conf

log_format  debug     '$remote_addr - $http_route_tag - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$http_x_xsrf_token"';


server {
    .
    .

    access_log /var/log/nginx/access.log  debug;
    .
    .

AWS Cloud Front by Terraform

But you may know about the limitations of this approach (scaling, CDN friendly, integrated in cloud...). So you may find aws-terraform directory Which will do the same in AWS CDN CloudFront. With a Cloudfront function for Viewer request the function is some line of code is JS as this is the default way to manipulate the HTTP Headers on the fly in CF. I didn't use Lambda@Edge because of its price, and of course It was nice handled by Cloudfront function.

http-header-modify-route-tagger's People

Watchers

Amir Dezfulian 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.