Skip to content

Conversation

@binhnguyenduc
Copy link

The proxy middleware currently does not allow any modification to the request, only ModifyResponse. This PR adds that option so caller can pass a custom function to be applied to requests before it hits reverse proxy.

I have also added passing test.

Please consider merging this as it would allow for more flexibility when proxy with Echo.

Thanks!

…es to http.Request before passing it to underlysing ReverseProxy
@@ -1,4 +1,4 @@
module github.com/labstack/echo/v4
module github.com/binhnguyenduc/echo/v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has to be removed

// Examples: If custom TLS certificates are required.
Transport http.RoundTripper

// ModifyRequest defines function to modify request before passing to ReverseProxy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Transport field provides similar functionality as you can create your own http.RoundTripper which modifies request:

type MyRoundTripper struct {
	accessToken string
	r           http.RoundTripper
}

func (mrt MyRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
	r.Header.Add("Authorization", "Bearer: "+mrt.accessToken)
	return mrt.r.RoundTrip(r)
}

func main() {
	e := echo.New()

	e.Use(middleware.ProxyWithConfig(middleware.ProxyConfig{
		Transport: MyRoundTripper{},
	}))

	log.Fatal(e.Start(":8080"))
}

https://stackoverflow.com/questions/51325704/adding-a-default-http-header-in-go

@asad-awadia
Copy link

@aldas is it possible to modify the proxy target urls at runtime?

@aldas
Copy link
Contributor

aldas commented Feb 14, 2022

I think you are looking for:

ProxyBalancer interface {
and look how commonBalancer works

@asad-awadia
Copy link

@aldas oh so I can use the returned object from NewRoundRobinBalancer to change the proxy targets by calling the appropriate methods?

The interface is already implemented internally? I just have to call addTarget with the right parameter ?

@aldas aldas closed this Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants