pub struct Client { /* private fields */ }Expand description
HTTP client for the git-lfs API endpoints.
One instance per LFS endpoint URL. Client is cheap to clone and
shares an underlying connection pool, so clone freely.
§Authentication
Two complementary mechanisms:
Authpassed at construction is the initial auth, applied to every request with no retry on 401.- A credential helper attached via
Self::with_credential_helperis queried on a 401 response: the request is retried once with the filled-in credentials, and the helper is toldapproveorrejectbased on the second attempt’s outcome. Once a fill succeeds, the client remembers the credentials and uses them for subsequent requests, so the 401 dance happens at most once per process.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn batch(&self, req: &BatchRequest) -> Result<BatchResponse, ApiError>
pub async fn batch(&self, req: &BatchRequest) -> Result<BatchResponse, ApiError>
POST /objects/batch to negotiate transfer URLs.
Source§impl Client
impl Client
Sourcepub fn new(endpoint: Url, auth: Auth) -> Self
pub fn new(endpoint: Url, auth: Auth) -> Self
Build a client rooted at the given LFS endpoint.
endpoint is the LFS server URL (e.g.
https://git-server.com/foo/bar.git/info/lfs). Subpaths
(/objects/batch, /locks, …) are joined onto it per request.
Sourcepub fn with_http_client(endpoint: Url, auth: Auth, http: Client) -> Self
pub fn with_http_client(endpoint: Url, auth: Auth, http: Client) -> Self
Like new but reuses a caller-supplied reqwest::Client.
Useful for sharing a connection pool, custom timeouts, proxies, etc.
Sourcepub fn with_extra_headers_for_verbose(
self,
headers: Vec<(String, String)>,
) -> Self
pub fn with_extra_headers_for_verbose( self, headers: Vec<(String, String)>, ) -> Self
Tell the client which http.<url>.extraHeader values are
installed on the underlying reqwest::Client, so we can echo
them under GIT_CURL_VERBOSE.
Doesn’t change what’s sent: the reqwest client’s default_headers
already carries them.
Sourcepub fn with_ssh_resolver(self, resolver: SharedSshResolver) -> Self
pub fn with_ssh_resolver(self, resolver: SharedSshResolver) -> Self
Attach an SSH auth resolver.
Called once per request to resolve
git-lfs-authenticate output; a non-empty returned href
overrides the endpoint URL for that request and the returned
headers are merged in. Pass when the LFS endpoint is reached via
SSH (ssh://... URL or bare git@host:repo); leave unset for
pure-HTTPS endpoints.
Sourcepub fn with_cred_url(self, url: Url) -> Self
pub fn with_cred_url(self, url: Url) -> Self
Override the URL used for credential prompts and the
Git credentials for <url> not found wording.
Pass the git remote URL when it shares scheme+host with the LFS endpoint; otherwise leave unset and credentials key on the LFS endpoint.
Sourcepub fn with_credential_helper(self, helper: Arc<dyn Helper>) -> Self
pub fn with_credential_helper(self, helper: Arc<dyn Helper>) -> Self
Attach a credential helper.
On 401, the client will call helper.fill, retry once with the
result, then approve/reject based on the outcome.
Sourcepub fn with_use_http_path(self, on: bool) -> Self
pub fn with_use_http_path(self, on: bool) -> Self
Toggle credential.useHttpPath.
When true, the endpoint URL’s path is included in the credential-fill
query (so a helper can scope per-repo); when false (the default,
matching git), only protocol+host are sent.
Sourcepub fn endpoint(&self) -> &Url
pub fn endpoint(&self) -> &Url
Read-only access to the endpoint URL this client was built against.
Used by callers that want to persist
lfs.<url>.access after a successful authenticated request.
Sourcepub fn used_basic_auth(&self) -> bool
pub fn used_basic_auth(&self) -> bool
Check if this client’s current auth state is basic (username/password).
Used by callers to detect whether the
most recent operation actually used basic auth, so they can
persist lfs.<url>.access = basic to local git config.
Source§impl Client
impl Client
Sourcepub async fn create_lock(
&self,
req: &CreateLockRequest,
) -> Result<Lock, CreateLockError>
pub async fn create_lock( &self, req: &CreateLockRequest, ) -> Result<Lock, CreateLockError>
POST /locks to create a new lock.
Body decoding is flexible to accommodate both spec’d 409 → existing
lock responses and the reference test server’s “200 with message
but no lock” in-band-conflict pattern.
Sourcepub async fn list_locks(
&self,
filter: &ListLocksFilter,
) -> Result<LockList, ApiError>
pub async fn list_locks( &self, filter: &ListLocksFilter, ) -> Result<LockList, ApiError>
GET /locks with optional filters. SSH-resolved as a download
operation (read-only listing).
Sourcepub async fn verify_locks(
&self,
req: &VerifyLocksRequest,
) -> Result<VerifyLocksResponse, ApiError>
pub async fn verify_locks( &self, req: &VerifyLocksRequest, ) -> Result<VerifyLocksResponse, ApiError>
POST /locks/verify to list locks partitioned into ours/theirs.
Per the spec, servers that don’t implement locking can return 404
here; that surfaces as ApiError::Status { status: 404, .. }. The
caller (typically push) should treat that as “no locks to verify”
rather than a hard failure — see is_not_found().
Sourcepub async fn delete_lock(
&self,
id: &str,
req: &DeleteLockRequest,
) -> Result<Lock, ApiError>
pub async fn delete_lock( &self, id: &str, req: &DeleteLockRequest, ) -> Result<Lock, ApiError>
POST /locks/{id}/unlock to delete a lock.