@@ -11,6 +11,7 @@ use std::{
11
11
12
12
use anyhow:: { bail, Context as _, Result } ;
13
13
use clap:: Parser ;
14
+ use http:: StatusCode ;
14
15
use iroh_base:: NodeId ;
15
16
use iroh_relay:: {
16
17
defaults:: {
@@ -184,8 +185,8 @@ enum AccessConfig {
184
185
Denylist ( Vec < NodeId > ) ,
185
186
/// Performs a HTTP POST request to determine access for each node that connects to the relay.
186
187
///
187
- /// The string value is used as the URL template, where `{node_id}` will be replaced
188
- /// with the hex-encoded node id that is connecting .
188
+ /// The request will have a header `X-Iroh-Node-Id` set to the hex-encoded node id attempting
189
+ /// to connect to the relay .
189
190
///
190
191
/// To grant access, the HTTP endpoint must return a `200` response with `true` as the response text.
191
192
/// In all other cases, the node will be denied access.
@@ -243,7 +244,7 @@ async fn http_access_check(
243
244
node_id : NodeId ,
244
245
) -> iroh_relay:: server:: Access {
245
246
use iroh_relay:: server:: Access ;
246
- debug ! ( %url, "check relay access via HTTP POST" ) ;
247
+ debug ! ( %url, "Check relay access via HTTP POST" ) ;
247
248
let res = match client
248
249
. post ( url)
249
250
. header ( "X-Iroh-NodeId" , node_id. to_string ( ) )
@@ -252,28 +253,28 @@ async fn http_access_check(
252
253
{
253
254
Ok ( t) => t,
254
255
Err ( err) => {
255
- warn ! ( "request failed: {err}" ) ;
256
+ warn ! ( "HTTP access check failed to retrieve response : {err}" ) ;
256
257
return Access :: Deny ;
257
258
}
258
259
} ;
259
- if res. status ( ) . is_success ( ) {
260
+ if res. status ( ) == StatusCode :: OK {
260
261
match res. text ( ) . await {
261
- Err ( err) => {
262
- warn ! ( "failed to read response: {err}" ) ;
263
- Access :: Deny
264
- }
265
262
Ok ( text) if text == "true" => {
266
- debug ! ( "request successfull : grant access" ) ;
263
+ debug ! ( "HTTP access check successful : grant access. " ) ;
267
264
Access :: Allow
268
265
}
269
266
Ok ( _) => {
270
- warn ! ( "request successfull but response text is not `true`: deny access" ) ;
267
+ warn ! ( "HTTP access check return invalid response text: deny access." ) ;
268
+ Access :: Deny
269
+ }
270
+ Err ( err) => {
271
+ warn ! ( "HTTP access check failed to read response: {err}" ) ;
271
272
Access :: Deny
272
273
}
273
274
}
274
275
} else {
275
276
debug ! (
276
- "request returned non-success code {}: deny access" ,
277
+ "HTTP access check response has status code {}: deny access" ,
277
278
res. status( )
278
279
) ;
279
280
Access :: Deny
0 commit comments