This commit is contained in:
gospider
2025-02-17 18:01:11 +08:00
parent d9161d1aee
commit fa2e44ae28
2 changed files with 13 additions and 5 deletions

10
body.go
View File

@@ -122,15 +122,19 @@ func (obj *OrderMap) parseForm(ctx context.Context) (io.Reader, string, bool, er
return nil, "", false, nil
}
if obj.isformPip() {
pr, pw := pipe(ctx)
pr, pw := io.Pipe()
writer := multipart.NewWriter(pw)
go func() {
context.AfterFunc(ctx, func() {
pr.CloseWithError(ctx.Err())
pw.CloseWithError(ctx.Err())
})
err := obj.formWriteMain(writer)
if err == nil {
err = io.EOF
}
pr.CloseWitError(err)
pw.CloseWitError(err)
pr.CloseWithError(err)
pw.CloseWithError(err)
}()
return pr, writer.FormDataContentType(), true, nil
}

View File

@@ -34,15 +34,19 @@ func newConn(ctx context.Context, con net.Conn, closeFunc func()) *conn {
conn: con,
closeFunc: closeFunc,
}
pr, pw := pipe(ctx)
pr, pw := io.Pipe()
c.r = bufio.NewReader(pr)
c.w = bufio.NewWriter(c)
go func() {
context.AfterFunc(ctx, func() {
pr.CloseWithError(ctx.Err())
pw.CloseWithError(ctx.Err())
})
_, err := io.Copy(pw, c.conn)
if c.err == nil {
c.CloseWithError(err)
}
pr.CloseWitError(c.err)
pr.CloseWithError(c.err)
}()
return c
}