Forward path and query string through proxy

Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis
2017-10-10 08:22:12 +01:00
parent 8ae81dad01
commit dde98eb582
4 changed files with 125 additions and 7 deletions

View File

@ -0,0 +1,29 @@
package requests
import "fmt"
import "net/url"
// ForwardRequest for proxying incoming requests
type ForwardRequest struct {
RawPath string
RawQuery string
Method string
}
// NewForwardRequest create a ForwardRequest
func NewForwardRequest(method string, url url.URL) ForwardRequest {
return ForwardRequest{
Method: method,
RawQuery: url.RawQuery,
RawPath: url.Path,
}
}
// ToURL create formatted URL
func (f *ForwardRequest) ToURL(addr string, watchdogPort int) string {
if len(f.RawQuery) > 0 {
return fmt.Sprintf("http://%s:%d%s?%s", addr, watchdogPort, f.RawPath, f.RawQuery)
}
return fmt.Sprintf("http://%s:%d%s", addr, watchdogPort, f.RawPath)
}