You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, is there any way to set the IP address of the mock request? I have a use case where I need to know the IP address of the incoming request. The library sets the IP address to an empty string. I need to set it to a particular value (could default to 127.0.0.1). Any help would be much appreciated.
Thanks
The text was updated successfully, but these errors were encountered:
I've been doing this by setting a fake server address directly after creating the engine:
e := NewEngine()
e.Server.Addr = FakeServerAddress
Rather than using c.Request().Host directly this must be matched on the server side with something like:
// get the IP address of the running server
func GetServerAddress(c echo.Context) string {
serverAddress := c.Request().Host
if serverAddress == "" {
// normally we use the address given in the HTTP request
// this is not set by gofight in unit tests so we use the listener address instead
if c.Echo().Server != nil {
serverAddress = c.Echo().Server.Addr
} else if c.Echo().Listener != nil {
serverAddress = c.Echo().Listener.Addr().String()
}
}
return serverAddress
}
as this could be a different IP & port. For example, if your server is running inside a docker container.
Hi, is there any way to set the IP address of the mock request? I have a use case where I need to know the IP address of the incoming request. The library sets the IP address to an empty string. I need to set it to a particular value (could default to 127.0.0.1). Any help would be much appreciated.
Thanks
The text was updated successfully, but these errors were encountered: