File tree Expand file tree Collapse file tree 1 file changed +27
-8
lines changed Expand file tree Collapse file tree 1 file changed +27
-8
lines changed Original file line number Diff line number Diff line change 1
- use std:: { str:: FromStr , sync:: Arc } ;
1
+ use std:: { io :: Read , str:: FromStr , sync:: Arc } ;
2
2
3
3
use aws_sdk_bedrockruntime:: { config, error:: ConnectorError } ;
4
4
use aws_smithy_runtime_api:: {
@@ -82,13 +82,11 @@ impl WasiConnector {
82
82
) ;
83
83
}
84
84
85
- let mut request = self . 0 . request ( method, url) . headers ( header_map) ;
86
-
87
- if let Some ( bytes) = parts. body . bytes ( ) {
88
- request = request. body ( bytes. to_owned ( ) ) ;
89
- }
90
-
91
- request
85
+ let body_reader = BodyReader :: new ( parts. body ) ;
86
+ self . 0
87
+ . request ( method, url)
88
+ . headers ( header_map)
89
+ . body ( reqwest:: Body :: new ( body_reader) )
92
90
. send ( )
93
91
. await
94
92
. map_err ( |e| ConnectorError :: other ( e. into ( ) , None ) )
@@ -138,3 +136,24 @@ impl HttpConnector for SharedWasiConnector {
138
136
HttpConnectorFuture :: new ( UnsafeFuture :: new ( future) )
139
137
}
140
138
}
139
+
140
+ struct BodyReader {
141
+ body : SdkBody ,
142
+ }
143
+
144
+ impl BodyReader {
145
+ fn new ( body : SdkBody ) -> Self {
146
+ Self { body }
147
+ }
148
+ }
149
+
150
+ impl Read for BodyReader {
151
+ fn read ( & mut self , buf : & mut [ u8 ] ) -> std:: io:: Result < usize > {
152
+ let bytes = self . body . bytes ( ) ;
153
+
154
+ match bytes {
155
+ Some ( mut bytes) => bytes. read ( buf) ,
156
+ None => Ok ( 0 ) ,
157
+ }
158
+ }
159
+ }
You can’t perform that action at this time.
0 commit comments