elazarl / goproxy

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

Question about modifying requests #517

Closed bjoernw closed 6 months ago

bjoernw commented 7 months ago

I'm trying to intercept grpc traffic via TLS and mutate request bodies before sending them on to the destination. I'm decompressing payloads, de-serializing them, mutating them, then compressing them again, setting the new request.Body and then setting the Content-Length header. I'm curious if this is something that's supported since I haven't seen any examples of how to do this and I'm continuously running into the following error message.

2023/11/18 23:20:09 [014] WARN: Cannot read TLS response from mitm'd server net/http: HTTP/1.x transport connection broken: http: ContentLength=17918 with Body length 17858       

Even though I set the Content-Length header to 17858. Does the header get dropped somewhere?

Any help would be greatly appreciated! Thanks!

FIXED

You have to set the ContentLength property on the request object, not just the header.