@@ -101,20 +101,13 @@ async fn handle(
101
101
_ => {
102
102
let proxy_req_result = ProxyRequest :: new ( & mut hyper_req, & state) . await ;
103
103
if proxy_req_result. is_none ( ) {
104
- return Ok ( Response :: builder ( )
105
- . status ( StatusCode :: BAD_GATEWAY )
106
- . body ( full ( "Invalid hostname" ) )
107
- . unwrap ( ) ) ;
108
- }
109
-
110
- let proxy_req = proxy_req_result. unwrap ( ) ;
111
- if proxy_req. consumer . is_none ( ) {
112
104
return Ok ( Response :: builder ( )
113
105
. status ( StatusCode :: UNAUTHORIZED )
114
106
. body ( full ( "Unauthorized" ) )
115
107
. unwrap ( ) ) ;
116
108
}
117
109
110
+ let proxy_req = proxy_req_result. unwrap ( ) ;
118
111
let response_result = match proxy_req. protocol {
119
112
Protocol :: Http => handle_http ( hyper_req, & proxy_req) . await ,
120
113
Protocol :: Websocket => handle_websocket ( hyper_req, & proxy_req, state. clone ( ) ) . await ,
@@ -199,11 +192,7 @@ async fn handle_websocket(
199
192
while let Some ( result) = client_incoming. next ( ) . await {
200
193
match result {
201
194
Ok ( data) => {
202
- if let Err ( err) = limiter (
203
- state. clone ( ) ,
204
- proxy_req. consumer . clone ( ) . as_ref ( ) . unwrap ( ) ,
205
- )
206
- . await
195
+ if let Err ( err) = limiter ( state. clone ( ) , & proxy_req. consumer ) . await
207
196
{
208
197
error ! ( error = err. to_string( ) , "Failed to run limiter" ) ;
209
198
break ;
@@ -276,7 +265,7 @@ pub struct ProxyRequest {
276
265
pub namespace : String ,
277
266
pub host : String ,
278
267
pub instance : String ,
279
- pub consumer : Option < Consumer > ,
268
+ pub consumer : Consumer ,
280
269
pub protocol : Protocol ,
281
270
}
282
271
impl ProxyRequest {
@@ -288,11 +277,6 @@ impl ProxyRequest {
288
277
let network = captures. get ( 2 ) ?. as_str ( ) . to_string ( ) ;
289
278
let version = captures. get ( 3 ) ?. as_str ( ) . to_string ( ) ;
290
279
291
- let instance = format ! (
292
- "ogmios-{network}-{version}.{}:{}" ,
293
- state. config. ogmios_dns, state. config. ogmios_port
294
- ) ;
295
-
296
280
let namespace = state. config . proxy_namespace . clone ( ) ;
297
281
298
282
let protocol = get_header ( hyper_req, UPGRADE . as_str ( ) )
@@ -314,7 +298,11 @@ impl ProxyRequest {
314
298
}
315
299
316
300
let token = get_header ( hyper_req, DMTR_API_KEY ) . unwrap_or_default ( ) ;
317
- let consumer = state. get_consumer ( & network, & version, & token) . await ;
301
+ let consumer = state. get_consumer ( & token) . await ?;
302
+ let instance = format ! (
303
+ "ogmios-{network}-{version}.{}:{}" ,
304
+ state. config. ogmios_dns, state. config. ogmios_port
305
+ ) ;
318
306
319
307
Some ( Self {
320
308
namespace,
0 commit comments