Skip to content

Commit

Permalink
fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
reakaleek committed Nov 22, 2024
1 parent 544293e commit 49c334b
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,22 @@ func handler(targets []string, w http.ResponseWriter, r *http.Request) {

func forwardRequest(target string, r *http.Request, ch chan *http.Response) {
// Create a copy of the request body
var bodyBytes []byte
if r.Body != nil {
bodyBytes, _ = io.ReadAll(r.Body)
}
bodyBytes, _ := io.ReadAll(r.Body)
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

// Parse the target URL
url, err := url.Parse(target)
u, err := url.Parse(target)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing target URL: %v\n", err)
ch <- nil
return
}
// Append the original request's path to the target URL
url.Path = r.URL.Path
url.RawQuery = r.URL.RawQuery // Include the query string
u.Path = r.URL.Path
u.RawQuery = r.URL.RawQuery // Include the query string

// Create a new request with the same method and URL
req, err := http.NewRequest(r.Method, url.String(), bytes.NewBuffer(bodyBytes)) // Use the copied body here
req, err := http.NewRequest(r.Method, u.String(), bytes.NewBuffer(bodyBytes)) // Use the copied body here
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating new request: %v\n", err)
ch <- nil
Expand Down

0 comments on commit 49c334b

Please sign in to comment.