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..fa70ee781a 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. ///