Giter VIP home page Giter VIP logo

go-lang's Introduction

go-lang

Reverse Proxy with Request and Response Modification

This Go program demonstrates the implementation of a reverse proxy server using the net/http package. The reverse proxy modifies both incoming requests and outgoing responses, specifically replacing occurrences of "demo.miniorange" with "example" in the request headers, response headers, and response body.

Code Overview

Custom Transport

The transport type is a custom implementation of the http.RoundTripper interface. It is responsible for modifying both requests and responses.

  • RoundTrip: This method intercepts the HTTP request, modifies its host and performs the actual round trip. It then processes the response, replacing relevant information.

Main Function

The main function initializes the reverse proxy and sets up a simple HTTP server.

  • Target URL Parsing: The target URL (https://demo.miniorange.com) is parsed using url.Parse.

  • Reverse Proxy Configuration:

    • A reverse proxy is created using httputil.NewSingleHostReverseProxy with a custom transport.
    • The Director function is set to modify the request before it is sent.
  • HTTP Server Configuration:

    • Requests for the root path ("/") are handled by the reverse proxy.
    • The server listens on port 443 with TLS using http.ListenAndServeTLS.

TLS Configuration

The server is configured to listen on port 443 with TLS, and TLS certificates are provided (example.com.crt and example.com.key).

Running the Code

To run the code, ensure that the necessary dependencies are installed, and then execute the following:

go run main.go

go-lang's People

Contributors

nitingupta-123 avatar

Watchers

 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.