1
+ use std:: io:: Cursor ;
2
+
1
3
use anyhow:: { Result , anyhow} ;
2
4
use auto_hash_map:: AutoSet ;
3
5
use futures:: { StreamExt , TryStreamExt } ;
@@ -94,7 +96,8 @@ pub async fn process_request_with_content_source(
94
96
Some ( "get_from_source_operation" ) ,
95
97
)
96
98
. await ?;
97
- match & * resolved_result. await ? {
99
+ let result = resolved_result. await ?;
100
+ match & * result {
98
101
GetFromSourceResult :: Static {
99
102
content,
100
103
status_code,
@@ -172,11 +175,15 @@ pub async fn process_request_with_content_source(
172
175
}
173
176
174
177
let content = file. content ( ) ;
178
+ // We already have all the bytes in memory
179
+ let content = content. to_bytes ( ) ?. into_owned ( ) ;
175
180
let response = if should_compress {
176
181
header_map. insert ( CONTENT_ENCODING , HeaderValue :: from_static ( "gzip" ) ) ;
177
182
178
183
// Grab ropereader stream, coerce anyhow::Error to std::io::Error
179
- let stream_ext = content. read ( ) . into_stream ( ) . map_err ( std:: io:: Error :: other) ;
184
+ let stream_ext = ReaderStream :: new ( Cursor :: new ( content) )
185
+ . into_stream ( )
186
+ . map_err ( std:: io:: Error :: other) ;
180
187
181
188
let gzipped_stream =
182
189
ReaderStream :: new ( async_compression:: tokio:: bufread:: GzipEncoder :: new (
@@ -190,7 +197,7 @@ pub async fn process_request_with_content_source(
190
197
hyper:: header:: HeaderValue :: try_from ( content. len ( ) . to_string ( ) ) ?,
191
198
) ;
192
199
193
- response. body ( hyper:: Body :: wrap_stream ( ReaderStream :: new ( content. read ( ) ) ) ) ?
200
+ response. body ( hyper:: Body :: from ( content) ) ?
194
201
} ;
195
202
196
203
return Ok ( ( response, side_effects) ) ;
0 commit comments