Skip to content

Commit

Permalink
fix: compare 'Content-Type' header case-insensitively, as required by…
Browse files Browse the repository at this point in the history
… the http spec.
  • Loading branch information
Byron committed Sep 27, 2022
2 parents c845c16 + 7aa8ab8 commit 237682a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions git-transport/src/client/blocking_io/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ impl Transport<Impl> {

impl<H: Http> Transport<H> {
fn check_content_type(service: Service, kind: &str, headers: <H as Http>::Headers) -> Result<(), client::Error> {
let wanted_content_type = format!("Content-Type: application/x-{}-{}", service.as_str(), kind);
let wanted_content_type = format!("content-type: application/x-{}-{}", service.as_str(), kind);
if !headers
.lines()
.collect::<Result<Vec<_>, _>>()?
.iter()
.any(|l| l == &wanted_content_type)
.any(|l| l.to_lowercase() == wanted_content_type)
{
return Err(client::Error::Http(Error::Detail {
description: format!(
Expand Down
12 changes: 12 additions & 0 deletions git-transport/tests/client/blocking_io/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,15 @@ Git-Protocol: version=2
);
Ok(())
}

#[test]
fn check_content_type_is_case_insensitive() -> crate::Result {
let (_server, mut client) = mock::serve_and_connect(
"v2/http-handshake-lowercase-headers.response",
"path/not/important/due/to/mock",
Protocol::V2,
)?;
let result = client.handshake(Service::UploadPack, &[]);
assert!(result.is_ok());
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
HTTP/1.1 200 OK
server: GitHub Babel 2.0
content-type: application/x-git-upload-pack-advertisement
content-length: 1000
expires: Fri, 01 Jan 1980 00:00:00 GMT
pragma: no-cache
cache-control: no-cache, max-age=0, must-revalidate
vary: Accept-Encoding
x-frame-options: DENY
x-github-request-id: 737D:544E:C932CB:113F404:5F3F3EE5

001e# service=git-upload-pack
0000000eversion 2
0023agent=git/github-gdf51a71f0236
000cls-refs
0019fetch=shallow filter
0012server-option
0000

0 comments on commit 237682a

Please sign in to comment.