Skip to content

Commit

Permalink
Fix Content-Length not being written
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinB committed Dec 18, 2020
1 parent 693e51e commit 2fc300f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ func (w *Writer) WriteRecord(r *Record) (recordID string, err error) {
return recordID, err
}

// Write headers
for key, value := range r.Header {
_, err = io.WriteString(w.fileWriter, strings.Title(key)+": "+value+"\r\n")
if err != nil {
return recordID, err
}
}

// If PayloadPath isn't empty, it means that the payload we need to write
// lives on disk
if r.PayloadPath != "" {
Expand Down Expand Up @@ -116,18 +108,34 @@ func (w *Writer) WriteRecord(r *Record) (recordID string, err error) {
}
}

// Write headers
r.Header["content-length"] = strconv.Itoa(contentLength)
for key, value := range r.Header {
_, err = io.WriteString(w.fileWriter, strings.Title(key)+": "+value+"\r\n")
if err != nil {
return recordID, err
}
}

_, err = io.WriteString(w.fileWriter, "\r\n\r\n")
if err != nil {
return recordID, err
}

r.Header["content-length"] = strconv.Itoa(contentLength)
} else {
data, err := ioutil.ReadAll(r.Content)
if err != nil {
return recordID, err
}

// Write headers
r.Header["content-length"] = strconv.Itoa(len(data))
for key, value := range r.Header {
_, err = io.WriteString(w.fileWriter, strings.Title(key)+": "+value+"\r\n")
if err != nil {
return recordID, err
}
}

_, err = io.WriteString(w.fileWriter, "\r\n"+string(data)+"\r\n\r\n")
if err != nil {
return recordID, err
Expand Down

0 comments on commit 2fc300f

Please sign in to comment.