Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/internal/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ impl HostScope {

/// Scope of a request URL (returns None for non-token-eligible schemes).
pub fn from_request_url(url: &url::Url) -> Option<HostScope> {
Self::from_url(url).ok()
// Request URLs necessarily contain repository and protocol paths, while
// stored credentials are scoped only to the origin host and port.
// Normalize the request to the origin before applying the strict host
// parser; otherwise every Git Smart HTTP request silently misses the
// stored token and push/fetch falls through to a 401 prompt.
let mut origin = url.clone();
origin.set_path("/");
origin.set_query(None);
origin.set_fragment(None);
Self::from_url(&origin).ok()
}

fn from_url(url: &url::Url) -> Result<HostScope> {
Expand Down
13 changes: 8 additions & 5 deletions src/internal/protocol/https_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{io::Error as IoError, ops::Deref, sync::Mutex, time::Duration};

use futures_util::{StreamExt, TryStreamExt};
use git_internal::errors::GitError;
use reqwest::{Body, RequestBuilder, Response, StatusCode, header::CONTENT_TYPE};
use reqwest::{RequestBuilder, Response, StatusCode, header::CONTENT_TYPE};
use url::Url;

use super::{
Expand Down Expand Up @@ -464,10 +464,7 @@ impl HttpsClient {
Ok(result)
}

pub async fn send_pack<T: Into<Body> + Clone>(
&self,
data: T,
) -> Result<Response, reqwest::Error> {
pub async fn send_pack(&self, data: bytes::Bytes) -> Result<Response, reqwest::Error> {
// INVARIANT: "git-receive-pack" is a valid relative URL onto self.url.
let receive_pack_url = self
.url
Expand All @@ -477,6 +474,12 @@ impl HttpsClient {
self.client
.post(receive_pack_url.clone())
.header(CONTENT_TYPE, "application/x-git-receive-pack-request")
.header(
reqwest::header::ACCEPT,
"application/x-git-receive-pack-result",
)
.header(reqwest::header::USER_AGENT, "git/2.43.0 libra")
.header(reqwest::header::CONTENT_LENGTH, data.len())
.body(data.clone())
})
.await
Expand Down
Loading