-
Notifications
You must be signed in to change notification settings - Fork 418
Make transport::Service
Debug
and add some HTTP constants from libgit2.
#1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
/// <https://github.com/libgit2/libgit2/blob/2ecc8586f7eec4063b5da1563d0a33f9e9f9fcf7/src/libgit2/transports/http.c#L68-L95>. | ||
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a public interface exposed by libgit2? If not I tend not to add this. We don't really want to get into troubles that there is no stability guarantee in libgit2 while git2-rs exposes it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The entire There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really appreciate your understanding. Yeah we need to weight on that. Anyway, as GitHub keeps diff in a pull request indefinitely, this can be used as a reference when people need such a glue code, which is great! Per discussion, I am going to close this and thank you again! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course! You're welcome! |
||
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. | ||
/// | ||
|
Uh oh!
There was an error while loading. Please reload this page.