elazarl / goproxy

An HTTP proxy library for Go
BSD 3-Clause "New" or "Revised" License
6k stars 1.09k forks source link

Possible to use with go-httpstat? #304

Open damien-roche opened 6 years ago

damien-roche commented 6 years ago

I am attempting to use goproxy with the following lib: https://github.com/tcnksm/go-httpstat

I currently trace requests doing something like this:

        var result httpstat.Result

        octx := httpstat.WithHTTPStat(req.Context(), &result)
        req = req.WithContext(octx)

        var client = &http.Client{
            Transport: &http.Transport{
                MaxIdleConnsPerHost: 0,
                DisableKeepAlives: true,
            },
            Timeout: time.Millisecond * 10000,
        }

        res, err := client.Do(req)

I noticed in the documentation I can set request headers, but not sure if/how I have such control over the request as above.

I have attempted to use proxy.OnRequest().DoFunc() and am returning in that function my req/res (from docs if I return response then request will be ignored), but have received an error "invalid Read on closed Body".

Appreciate any pointers.

elazarl commented 6 years ago

Hi, I apologize, but I don't have time to look at it currently.

I hope someone else would be able to answer.

On Wed, Aug 1, 2018 at 11:22 AM Damien Roche notifications@github.com wrote:

I am attempting to use goproxy with the following lib: https://github.com/tcnksm/go-httpstat

I currently trace requests doing something like this:

  var result httpstat.Result

  octx := httpstat.WithHTTPStat(req.Context(), &result)
  req = req.WithContext(octx)

  var client = &http.Client{
      Transport: &http.Transport{
          MaxIdleConnsPerHost: 0,
          DisableKeepAlives: true,
      },
      Timeout: time.Millisecond * 10000,
  }

  res, err := client.Do(req)

I noticed in the documentation I can set request headers, but not sure if/how I can override the actual request handling.

I have attempted to use proxy.OnRequest().DoFunc() and am returning in that function my req/res from above (from docs if I return response then request will be ignored), but have received an error "invalid Read on closed Body".

Appreciate any pointers.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/elazarl/goproxy/issues/304, or mute the thread https://github.com/notifications/unsubscribe-auth/AAP4ovdQf9b1pXuRCdGH4bsFqttztMHpks5uMWVQgaJpZM4VqDkt .

damien-roche commented 6 years ago

No probs.

I've moved away from go-httpstat to simply wrap the net/http and use net/http/httptrace directly.

My intention above was to perform a request using the proxy server and return metrics in the headers of the response.