Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Request time out for deflate compression with http 2 #152

Open
kashif-ghafoor opened this issue Jan 3, 2025 · 1 comment
Open
Labels
bug Something isn't working

Comments

@kashif-ghafoor
Copy link

TLS client version

v1.7.10

System information

Model Name: MacBook Pro
Chip: Apple M1 Pro
Total Number of Cores: 10 (8 performance and 2 efficiency)
Memory: 16 GB

Issue description

I recieve following error
failed to do request: Get "https://httpbin.org/deflate": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
when making request with tls-client.

I think it's related to decompression. It works for gzip and brotli compression but gives error for deflate.

Steps to reproduce / Code Sample

package main

import (
	"fmt"
	"io"
	"strings"

	fhttp "github.com/bogdanfinn/fhttp"
	tls_client "github.com/bogdanfinn/tls-client"
	profiles "github.com/bogdanfinn/tls-client/profiles"
)	

func main() {
	// Create client with Firefox browser profile
	options := []tls_client.HttpClientOption{
		tls_client.WithTimeoutSeconds(30),
		tls_client.WithClientProfile(profiles.Chrome_131),
		tls_client.WithDebug(),
		// tls_client.WithForceHttp1(),
	}

	client, err := tls_client.NewHttpClient(tls_client.NewNoopLogger(), options...)
	if err != nil {
		fmt.Printf("Failed to create client: %v\n", err)
		return
	}
	url := "https://httpbin.org/deflate"

	// Create a test request
	req, err := fhttp.NewRequest("GET", url, strings.NewReader(""))
	if err != nil {
		fmt.Printf("Failed to create request: %v\n", err)
		return
	}

	// Set some basic headers
	req.Header = fhttp.Header{
		"accept":          {"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"},
		"accept-language": {"en-US,en;q=0.5"},
		"accept-encoding": {"deflate"},
		"user-agent":      {"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0"},
	}

	// Enable redirect following
	client.SetFollowRedirect(true)

	// Make the request
	fmt.Println("Sending request...")
	resp, err := client.Do(req)
	if err != nil {
		fmt.Printf("Request failed: %v\n", err)
		return
	}
	defer resp.Body.Close()

	// Read and print response
	fmt.Printf("Status Code: %d\n", resp.StatusCode)
	fmt.Println("Headers:", resp.Header)


	// decomBody := fhttp.DecompressBody(resp)

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		fmt.Printf("Failed to read body: %v\n", err)
		return
	}
	
	fmt.Println("Body:", string(body))
} 
@kashif-ghafoor kashif-ghafoor added the bug Something isn't working label Jan 3, 2025
@kashif-ghafoor
Copy link
Author

disabling compression in client options and then decompressing the payload explicitly works fine.

	options := []tls_client.HttpClientOption{
		tls_client.WithTransportOptions(&tls_client.TransportOptions{
			DisableCompression: true,
		}),
	}
// make request
decomBody := fhttp.DecompressBody(resp)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant