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

Http proxy connection can not reuse between pixiu and upstream #558

Closed
mark4z opened this issue Apr 9, 2023 · 2 comments
Closed

Http proxy connection can not reuse between pixiu and upstream #558

mark4z opened this issue Apr 9, 2023 · 2 comments
Labels
good first issue Good for newcomers

Comments

@mark4z
Copy link
Member

mark4z commented Apr 9, 2023

There are two bugs on HTTP proxy.
[ ] We should reuse http.Client and let user custom it in the config, like MaxIdleConnsPerHost, etc.
[ ] We should close Body so that the connection can be reused.
What happened:
routerfiller.go

	req.Header = r.Header

        // creat http client too many times
	cli := &http3.Client{
		Transport: f.transport,
		Timeout:   hc.Timeout,
	}

	resp, err := cli.Do(req)

manger.go

func (hcm *HttpConnectionManager) buildTargetResponse(c *pch.HttpContext) {
	if c.LocalReply() {
		return
	}

	switch res := c.SourceResp.(type) {
	case *stdHttp.Response:
//It is the caller's responsibility to
	// close Body. The default HTTP client's Transport may not
	// reuse HTTP/1.x "keep-alive" TCP connections if the Body is
	// not read to completion and closed.
		body, err := io.ReadAll(res.Body)
		if err != nil {
			panic(err)
		}
		//Merge header
		remoteHeader := res.Header
		for k := range remoteHeader {
			c.AddHeader(k, remoteHeader.Get(k))
		}

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

@mark4z mark4z added the good first issue Good for newcomers label Apr 9, 2023
@jokercoldly
Copy link

Please assign it to me.

@mark4z
Copy link
Member Author

mark4z commented Apr 9, 2023

Please assign it to me.

as u wish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants