From bf9353dec1ef25de439b761745353a4b1ada962d Mon Sep 17 00:00:00 2001 From: Northseadl Date: Sun, 8 Jan 2023 00:47:40 +0800 Subject: [PATCH] fix multipart last part boundary --- http/contract/dataflowInterface.go | 1 + http/dataflow/dataflow.go | 7 ++++++- http/dataflow/mutlipart.go | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/http/contract/dataflowInterface.go b/http/contract/dataflowInterface.go index ea9dcc7..3a88cfb 100644 --- a/http/contract/dataflowInterface.go +++ b/http/contract/dataflowInterface.go @@ -56,6 +56,7 @@ type MultipartDfInterface interface { Part(header textproto.MIMEHeader, reader io.Reader) MultipartDfInterface FieldValue(fieldName string, value string) MultipartDfInterface Field(fieldName string, reader io.Reader) MultipartDfInterface + Close() error GetBoundary() string GetReader() io.Reader GetContentType() string diff --git a/http/dataflow/dataflow.go b/http/dataflow/dataflow.go index 0215be2..d54f107 100644 --- a/http/dataflow/dataflow.go +++ b/http/dataflow/dataflow.go @@ -220,7 +220,12 @@ func (d *Dataflow) Xml(xmlAny interface{}) contract.RequestDataflowInterface { func (d *Dataflow) Multipart(multipartDf func(multipart contract.MultipartDfInterface)) contract.RequestDataflowInterface { multipart := NewMultipartHelper() multipartDf(multipart) - err := multipart.Err() + err := multipart.Close() + if err != nil { + d.err = append(d.err, err) + return d + } + err = multipart.Err() if err != nil { d.err = append(d.err, err) return d diff --git a/http/dataflow/mutlipart.go b/http/dataflow/mutlipart.go index d98dee4..1b62959 100644 --- a/http/dataflow/mutlipart.go +++ b/http/dataflow/mutlipart.go @@ -120,6 +120,10 @@ func (m *MultipartDf) Field(fieldName string, reader io.Reader) contract.Multipa return m } +func (m *MultipartDf) Close() error { + return m.mWriter.Close() +} + func (m *MultipartDf) GetBoundary() string { return m.mWriter.Boundary() }