@@ -27,34 +27,15 @@ const MAX_HTTP_MESSAGE_BODY_SIZE: usize = 2 * 4_000_000 + 64;
27
27
/// Endpoint for interacting with an HTTP-based API.
28
28
#[ derive( Debug ) ]
29
29
pub struct HttpEndpoint {
30
- scheme : Scheme ,
31
30
host : String ,
32
31
port : Option < u16 > ,
33
32
path : String ,
34
33
}
35
34
36
- /// URI scheme compatible with an HTTP endpoint.
37
- #[ derive( Debug ) ]
38
- pub enum Scheme {
39
- HTTP ,
40
- HTTPS ,
41
- }
42
-
43
35
impl HttpEndpoint {
44
- /// Creates an endpoint using the HTTP scheme .
45
- pub fn insecure_host ( host : String ) -> Self {
36
+ /// Creates an endpoint for the given host and default HTTP port .
37
+ pub fn for_host ( host : String ) -> Self {
46
38
Self {
47
- scheme : Scheme :: HTTP ,
48
- host,
49
- port : None ,
50
- path : String :: from ( "/" ) ,
51
- }
52
- }
53
-
54
- /// Creates an endpoint using the HTTPS scheme.
55
- pub fn secure_host ( host : String ) -> Self {
56
- Self {
57
- scheme : Scheme :: HTTPS ,
58
39
host,
59
40
port : None ,
60
41
path : String :: from ( "/" ) ,
@@ -81,10 +62,7 @@ impl HttpEndpoint {
81
62
/// Returns the endpoint port.
82
63
pub fn port ( & self ) -> u16 {
83
64
match self . port {
84
- None => match self . scheme {
85
- Scheme :: HTTP => 80 ,
86
- Scheme :: HTTPS => 443 ,
87
- } ,
65
+ None => 80 ,
88
66
Some ( port) => port,
89
67
}
90
68
}
@@ -422,43 +400,36 @@ mod endpoint_tests {
422
400
use super :: HttpEndpoint ;
423
401
424
402
#[ test]
425
- fn to_insecure_host ( ) {
426
- let endpoint = HttpEndpoint :: insecure_host ( "foo.com" . into ( ) ) ;
403
+ fn with_default_port ( ) {
404
+ let endpoint = HttpEndpoint :: for_host ( "foo.com" . into ( ) ) ;
427
405
assert_eq ! ( endpoint. host( ) , "foo.com" ) ;
428
406
assert_eq ! ( endpoint. port( ) , 80 ) ;
429
407
}
430
408
431
- #[ test]
432
- fn to_secure_host ( ) {
433
- let endpoint = HttpEndpoint :: secure_host ( "foo.com" . into ( ) ) ;
434
- assert_eq ! ( endpoint. host( ) , "foo.com" ) ;
435
- assert_eq ! ( endpoint. port( ) , 443 ) ;
436
- }
437
-
438
409
#[ test]
439
410
fn with_custom_port ( ) {
440
- let endpoint = HttpEndpoint :: insecure_host ( "foo.com" . into ( ) ) . with_port ( 8080 ) ;
411
+ let endpoint = HttpEndpoint :: for_host ( "foo.com" . into ( ) ) . with_port ( 8080 ) ;
441
412
assert_eq ! ( endpoint. host( ) , "foo.com" ) ;
442
413
assert_eq ! ( endpoint. port( ) , 8080 ) ;
443
414
}
444
415
445
416
#[ test]
446
417
fn with_uri_path ( ) {
447
- let endpoint = HttpEndpoint :: insecure_host ( "foo.com" . into ( ) ) . with_path ( "/path" . into ( ) ) ;
418
+ let endpoint = HttpEndpoint :: for_host ( "foo.com" . into ( ) ) . with_path ( "/path" . into ( ) ) ;
448
419
assert_eq ! ( endpoint. host( ) , "foo.com" ) ;
449
420
assert_eq ! ( endpoint. path( ) , "/path" ) ;
450
421
}
451
422
452
423
#[ test]
453
424
fn without_uri_path ( ) {
454
- let endpoint = HttpEndpoint :: insecure_host ( "foo.com" . into ( ) ) ;
425
+ let endpoint = HttpEndpoint :: for_host ( "foo.com" . into ( ) ) ;
455
426
assert_eq ! ( endpoint. host( ) , "foo.com" ) ;
456
427
assert_eq ! ( endpoint. path( ) , "/" ) ;
457
428
}
458
429
459
430
#[ test]
460
431
fn convert_to_socket_addrs ( ) {
461
- let endpoint = HttpEndpoint :: insecure_host ( "foo.com" . into ( ) ) ;
432
+ let endpoint = HttpEndpoint :: for_host ( "foo.com" . into ( ) ) ;
462
433
let host = endpoint. host ( ) ;
463
434
let port = endpoint. port ( ) ;
464
435
@@ -569,8 +540,7 @@ pub(crate) mod client_tests {
569
540
}
570
541
571
542
pub fn endpoint ( & self ) -> HttpEndpoint {
572
- HttpEndpoint :: insecure_host ( self . address . ip ( ) . to_string ( ) )
573
- . with_port ( self . address . port ( ) )
543
+ HttpEndpoint :: for_host ( self . address . ip ( ) . to_string ( ) ) . with_port ( self . address . port ( ) )
574
544
}
575
545
}
576
546
0 commit comments