From 79b0d719ec46973a2cf9043f084d4d6f520bce65 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Thu, 21 Oct 2021 23:14:55 +0200 Subject: [PATCH] fix: read twice from body --- cmd/eksterd/memory.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/eksterd/memory.go b/cmd/eksterd/memory.go index 9ca9e1f..c54ede3 100644 --- a/cmd/eksterd/memory.go +++ b/cmd/eksterd/memory.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "io" + "io/ioutil" "log" "net/http" "net/url" @@ -589,8 +590,14 @@ func (b *memoryBackend) Events() (chan sse.Message, error) { // ProcessSourcedItems processes items and adds the Source func ProcessSourcedItems(fetcher fetch.FetcherFunc, fetchURL, contentType string, body io.Reader) ([]microsub.Item, error) { // When the source is available from the Header, we fill the Source of the item + + bodyBytes, err := ioutil.ReadAll(body) + if err != nil { + return nil, err + } + var source *microsub.Source - if header, err := fetch.FeedHeader(fetcher, fetchURL, contentType, body); err == nil { + if header, err := fetch.FeedHeader(fetcher, fetchURL, contentType, bytes.NewBuffer(bodyBytes)); err == nil { source = µsub.Source{ ID: header.URL, URL: header.URL, @@ -604,7 +611,7 @@ func ProcessSourcedItems(fetcher fetch.FetcherFunc, fetchURL, contentType string } } - items, err := fetch.FeedItems(fetcher, fetchURL, contentType, body) + items, err := fetch.FeedItems(fetcher, fetchURL, contentType, bytes.NewBuffer(bodyBytes)) if err != nil { return nil, err }