mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-01-05 17:13:32 +08:00
Fixed: handle chunked data
This commit is contained in:
parent
b6e4086556
commit
5fc6b17c1e
@ -32,7 +32,6 @@ func (h *HttpAdapter) Connect(proxy C.ProxyAdapter) {
|
|||||||
// from http.DefaultTransport
|
// from http.DefaultTransport
|
||||||
MaxIdleConns: 100,
|
MaxIdleConns: 100,
|
||||||
IdleConnTimeout: 90 * time.Second,
|
IdleConnTimeout: 90 * time.Second,
|
||||||
TLSHandshakeTimeout: 10 * time.Second,
|
|
||||||
ExpectContinueTimeout: 1 * time.Second,
|
ExpectContinueTimeout: 1 * time.Second,
|
||||||
}
|
}
|
||||||
resp, err := req.RoundTrip(h.r)
|
resp, err := req.RoundTrip(h.r)
|
||||||
@ -48,7 +47,23 @@ func (h *HttpAdapter) Connect(proxy C.ProxyAdapter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.w.WriteHeader(resp.StatusCode)
|
h.w.WriteHeader(resp.StatusCode)
|
||||||
io.Copy(h.w, resp.Body)
|
var writer io.Writer = h.w
|
||||||
|
if len(resp.TransferEncoding) > 0 && resp.TransferEncoding[0] == "chunked" {
|
||||||
|
writer = ChunkWriter{Writer: h.w}
|
||||||
|
}
|
||||||
|
io.Copy(writer, resp.Body)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChunkWriter struct {
|
||||||
|
io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cw ChunkWriter) Write(b []byte) (int, error) {
|
||||||
|
n, err := cw.Writer.Write(b)
|
||||||
|
if err == nil {
|
||||||
|
cw.Writer.(http.Flusher).Flush()
|
||||||
|
}
|
||||||
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttp(host string, w http.ResponseWriter, r *http.Request) (*HttpAdapter, chan struct{}) {
|
func NewHttp(host string, w http.ResponseWriter, r *http.Request) (*HttpAdapter, chan struct{}) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user