Skip to content

Commit a2575cc

Browse files
committed
f - Remove support for secure hosts
1 parent d65b5e1 commit a2575cc

File tree

1 file changed

+10
-40
lines changed

1 file changed

+10
-40
lines changed

lightning-block-sync/src/http.rs

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,15 @@ const MAX_HTTP_MESSAGE_BODY_SIZE: usize = 2 * 4_000_000 + 64;
2727
/// Endpoint for interacting with an HTTP-based API.
2828
#[derive(Debug)]
2929
pub struct HttpEndpoint {
30-
scheme: Scheme,
3130
host: String,
3231
port: Option<u16>,
3332
path: String,
3433
}
3534

36-
/// URI scheme compatible with an HTTP endpoint.
37-
#[derive(Debug)]
38-
pub enum Scheme {
39-
HTTP,
40-
HTTPS,
41-
}
42-
4335
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 {
4638
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,
5839
host,
5940
port: None,
6041
path: String::from("/"),
@@ -81,10 +62,7 @@ impl HttpEndpoint {
8162
/// Returns the endpoint port.
8263
pub fn port(&self) -> u16 {
8364
match self.port {
84-
None => match self.scheme {
85-
Scheme::HTTP => 80,
86-
Scheme::HTTPS => 443,
87-
},
65+
None => 80,
8866
Some(port) => port,
8967
}
9068
}
@@ -422,43 +400,36 @@ mod endpoint_tests {
422400
use super::HttpEndpoint;
423401

424402
#[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());
427405
assert_eq!(endpoint.host(), "foo.com");
428406
assert_eq!(endpoint.port(), 80);
429407
}
430408

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-
438409
#[test]
439410
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);
441412
assert_eq!(endpoint.host(), "foo.com");
442413
assert_eq!(endpoint.port(), 8080);
443414
}
444415

445416
#[test]
446417
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());
448419
assert_eq!(endpoint.host(), "foo.com");
449420
assert_eq!(endpoint.path(), "/path");
450421
}
451422

452423
#[test]
453424
fn without_uri_path() {
454-
let endpoint = HttpEndpoint::insecure_host("foo.com".into());
425+
let endpoint = HttpEndpoint::for_host("foo.com".into());
455426
assert_eq!(endpoint.host(), "foo.com");
456427
assert_eq!(endpoint.path(), "/");
457428
}
458429

459430
#[test]
460431
fn convert_to_socket_addrs() {
461-
let endpoint = HttpEndpoint::insecure_host("foo.com".into());
432+
let endpoint = HttpEndpoint::for_host("foo.com".into());
462433
let host = endpoint.host();
463434
let port = endpoint.port();
464435

@@ -569,8 +540,7 @@ pub(crate) mod client_tests {
569540
}
570541

571542
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())
574544
}
575545
}
576546

0 commit comments

Comments
 (0)