apache / dubbo-go-pixiu

Based on the proxy gateway service of dubbo-go, it solves the problem that the external protocol calls the internal Dubbo cluster. At present, it supports HTTP and gRPC[developing].
https://dubbogo.github.io/dubbo-go-proxy/
Apache License 2.0
488 stars 154 forks source link

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

Closed mark4z closed 1 year ago

mark4z commented 1 year ago

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?:

jokercoldly commented 1 year ago

Please assign it to me.

mark4z commented 1 year ago

Please assign it to me.

as u wish