Skip to content

Erorr reading body using DumpResponseHeadersAndRaw when proxy used #138

Closed
@RamanaReddy0M

Description

When we read the http response body received via proxy, we get both an error and a response(not empty).

In such cases httputils.DumpResponseHeadersAndRaw(..) return an empty response instead actual response.

Example to reproduce

package main

import (
	"crypto/tls"
	"fmt"
	"net/http"
	"net/url"

	pdhttputil "github.com/projectdiscovery/utils/http"
)

func main() {
	// Set the proxy URL
	proxyURL := "http://127.0.0.1:8081" // Update with your actual Burp Suite proxy URL

	// Create a proxy URL object
	proxy, err := url.Parse(proxyURL)
	if err != nil {
		fmt.Println("Failed to parse proxy URL:", err)
		return
	}

	// Create a custom HTTP transport with proxy settings
	transport := &http.Transport{
		Proxy: http.ProxyURL(proxy),
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true, // Ignore SSL certificate verification (for Burp Suite proxy)
		},
	}

	// Create an HTTP client with the custom transport
	client := &http.Client{
		Transport: transport,
	}

	// Create an HTTP request
	req, err := http.NewRequest("GET", "https://www.youtube.com", nil)
	if err != nil {
		fmt.Println("Failed to create request:", err)
		return
	}

	// Send the HTTP request via the Burp Suite proxy
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Failed to send request via proxy:", err)
		return
	}
	defer resp.Body.Close()

	//##Expected Behaviour
	// Read the response body using ioutils
	//body, err := ioutil.ReadAll(resp.Body)

	//##Current Behaviour
	// Read the response using pdhttputils
	_, body, err := pdhttputil.DumpResponseHeadersAndRaw(resp)

	// Print the response body
	fmt.Println("Body: ", string(body))
	// Err
	fmt.Println("ERROR: ", err)

}

Metadata

Assignees

Labels

Status: CompletedNothing further to be done with this issue. Awaiting to be closed.Type: BugInconsistencies or issues which will cause an issue or problem for users or implementors.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions