@@ -116,19 +116,13 @@ async fn send_reply(task: &TaskRequest<HttpRequest>, config: &Config, resp: Resu
116
116
}
117
117
}
118
118
119
- // TODO: Take ownership of `task` to save clones
120
119
async fn execute_http_task ( task : & TaskRequest < HttpRequest > , config : & Config ) -> Result < Response , BeamConnectError > {
121
120
let task_req = & task. body ;
122
- let span = Span :: current ( ) ;
123
- span. record ( "method" , field:: display ( & task_req. method ) ) ;
124
- span. record ( "orig_url" , field:: display ( & task_req. url ) ) ;
121
+ let vhost = task_req. url . authority ( ) . expect ( "Url has an authority" ) ;
125
122
let target = config
126
123
. targets_local
127
- . get ( task_req. url . authority ( ) . unwrap ( ) ) //TODO unwrap
128
- . ok_or_else ( || {
129
- warn ! ( "Lookup of local target {} failed" , task_req. url. authority( ) . unwrap( ) ) ;
130
- BeamConnectError :: CommunicationWithTargetFailed ( String :: from ( "Target not defined" ) )
131
- } ) ?;
124
+ . get ( vhost)
125
+ . ok_or_else ( || BeamConnectError :: NoLocalMapping ( vhost. clone ( ) ) ) ?;
132
126
match & task. from {
133
127
AppOrProxyId :: App ( app) if target. can_be_accessed_by ( app) => { } ,
134
128
id => return Err ( BeamConnectError :: IdNotAuthorizedToAccessUrl ( id. clone ( ) , task_req. url . clone ( ) ) ) ,
@@ -155,7 +149,7 @@ async fn execute_http_task(task: &TaskRequest<HttpRequest>, config: &Config) ->
155
149
. authority ( target. replace . authority . to_owned ( ) )
156
150
. build ( ) ?;
157
151
158
- span . record ( "dst_url" , field:: display ( & uri) ) ;
152
+ Span :: current ( ) . record ( "dst_url" , field:: display ( & uri) ) ;
159
153
let mut headers = task_req. headers . clone ( ) ;
160
154
if target. reset_host {
161
155
// This will lead to reqwest generating a new HOST header coresponding to the new hostname of the url.
@@ -171,7 +165,7 @@ async fn execute_http_task(task: &TaskRequest<HttpRequest>, config: &Config) ->
171
165
. body ( task_req. body . to_vec ( ) )
172
166
. send ( )
173
167
. await
174
- . map_err ( |e| BeamConnectError :: CommunicationWithTargetFailed ( e . to_string ( ) ) ) ?;
168
+ . map_err ( BeamConnectError :: CommunicationWithTargetFailed ) ?;
175
169
Ok ( resp)
176
170
}
177
171
0 commit comments