From 6cf01686c513a1d94b75b69bed6e7689fd26e5ce Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Fri, 25 Aug 2023 17:16:35 +0200 Subject: [PATCH] providers/redfish: return error instead of panic, include a few comments --- providers/redfish/firmware.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/providers/redfish/firmware.go b/providers/redfish/firmware.go index 2f3a17e2..d0293b73 100644 --- a/providers/redfish/firmware.go +++ b/providers/redfish/firmware.go @@ -208,10 +208,13 @@ type pipeReaderFakeSeeker struct { // Seek impelements the io.Seeker interface only to panic if called func (p pipeReaderFakeSeeker) Seek(offset int64, whence int) (int64, error) { - panic("Seek() not implemented for fake pipe reader seeker.") + return 0, errors.New("Seek() not implemented for fake pipe reader seeker.") } // multipartPayloadSize prepares a temporary multipart form to determine the form size +// +// It creates a temporary form without reading in the update file payload and returns +// sizeOf(form) + sizeOf(update file) func multipartPayloadSize(payload []map[string]io.Reader) (int64, *bytes.Buffer, error) { body := &bytes.Buffer{} form := multipart.NewWriter(body) @@ -290,7 +293,11 @@ func (c *Conn) runRequestWithMultipartPayload(method, url string, payload []map[ // A content-length header is passed in to indicate the payload size // - // The content-length is required since the + // The Content-length is set explicitly since the payload is an io.Reader, + // https://github.com/golang/go/blob/ddad9b618cce0ed91d66f0470ddb3e12cfd7eeac/src/net/http/request.go#L861 + // + // Without the content-length header the http client will set the Transfer-Encoding to 'chunked' + // and that does not work for some BMCs (iDracs). contentLength, _, err := multipartPayloadSize(payload) if err != nil { return nil, errors.Wrap(err, "error determining multipart payload size")