From bdd05c0652987896ee5776663db89da2cd219ae4 Mon Sep 17 00:00:00 2001 From: Venus Xeon-Blonde Date: Thu, 18 Jul 2024 14:23:08 -0400 Subject: [PATCH 1/2] Make `transport::Service` `Debug` and add http constants from libgit2's http transport implementation. --- Cargo.toml | 1 + src/transport.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9e6fd81f56..ef9197fd2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ bitflags = "2.1.0" libc = "0.2" log = "0.4.8" libgit2-sys = { path = "libgit2-sys", version = "0.17.0" } +http = "1.1" [target."cfg(all(unix, not(target_os = \"macos\")))".dependencies] openssl-sys = { version = "0.9.45", optional = true } diff --git a/src/transport.rs b/src/transport.rs index 3a4660627f..8260c0f5f8 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -54,7 +54,7 @@ pub trait SmartSubtransport: Send + 'static { } /// Actions that a smart transport can ask a subtransport to perform -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Debug)] #[allow(missing_docs)] pub enum Service { UploadPackLs, @@ -63,6 +63,51 @@ pub enum Service { ReceivePack, } +/// HTTP implementation related info for various services. +/// +/// This information was pulled from +/// . +impl Service { + /// The HTTP Method used by libgit2's implementation for http(s) transport. + pub const fn http_method(self) -> http::Method { + use http::Method; + + match self { + Service::UploadPackLs | Service::ReceivePackLs => Method::GET, + Service::UploadPack | Service::ReceivePack => Method::POST, + } + } + + /// The value of the HTTP "Accept" header that is used by libgit2's implementation for http(s) transport. + pub const fn http_accept_header(self) -> &'static str { + match self { + Service::UploadPackLs => "application/x-git-upload-pack-advertisement", + Service::ReceivePackLs => "application/x-git-receive-pack-advertisement", + Service::UploadPack => "application/x-git-upload-pack-result", + Service::ReceivePack => "application/x-git-receive-pack-result", + } + } + + /// The value of the HTTP "Content-Type" header that is used by libgit2's implementation for http(s) transport. + pub const fn http_content_type_header(self) -> Option<&'static str> { + match self { + Service::UploadPackLs | Service::ReceivePackLs => None, + Service::ReceivePack => Some("application/x-git-receive-pack-request"), + Service::UploadPack => Some("application/x-git-upload-pack-request"), + } + } + + /// The HTTP Url path and query suffix used by libgit2's implementation for http(s) transport. + pub const fn http_path_and_query(self) -> &'static str { + match self { + Service::UploadPackLs => "/info/refs?service=git-upload-pack", + Service::UploadPack => "/git-upload-pack", + Service::ReceivePackLs => "/info/refs?service=git-receive-pack", + Service::ReceivePack => "/git-receive-pack", + } + } +} + /// An instance of a stream over which a smart transport will communicate with a /// remote. /// From 797197caef0b9e9bd5842ead8c538778e04e588b Mon Sep 17 00:00:00 2001 From: Venus Xeon-Blonde Date: Thu, 18 Jul 2024 14:29:46 -0400 Subject: [PATCH 2/2] Remove trailing whitespace --- src/transport.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transport.rs b/src/transport.rs index 8260c0f5f8..fa70ee781a 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -64,9 +64,9 @@ pub enum Service { } /// HTTP implementation related info for various services. -/// -/// This information was pulled from -/// . +/// +/// This information was pulled from +/// . impl Service { /// The HTTP Method used by libgit2's implementation for http(s) transport. pub const fn http_method(self) -> http::Method {