Skip to content

Commit

Permalink
fix: close body before attempting to call finish (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Joonas Bergius <[email protected]>
  • Loading branch information
joonas authored Nov 6, 2024
1 parent 6a9a485 commit 594b764
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions net/wasihttp/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,23 @@ func (r *Transport) RoundTrip(incomingRequest *http.Request) (*http.Response, er
return nil, fmt.Errorf("failed to copy body: %v", err)
}

if err := adaptedBody.Close(); err != nil {
return nil, fmt.Errorf("failed to close body: %v", err)
}

outTrailers := types.NewFields()
if err := HTTPtoWASIHeader(incomingRequest.Trailer, outTrailers); err != nil {
return nil, err
}

outFinish := types.OutgoingBodyFinish(*body, cm.Some(outTrailers))
maybeTrailers := cm.None[types.Fields]()
if len(incomingRequest.Trailer) > 0 {
maybeTrailers = cm.Some(outTrailers)
}

outFinish := types.OutgoingBodyFinish(*body, maybeTrailers)
if outFinish.IsErr() {
return nil, fmt.Errorf("failed to set trailer: %v", outFinish.Err())
return nil, fmt.Errorf("failed to finish body: %v", outFinish.Err())
}
}

Expand Down

0 comments on commit 594b764

Please sign in to comment.