Repositories

grarr

(mirrored on github)

When there's a lot of refs git automatically gzips the request.

Modified Cargo.lock

@@ -3,24 +3,25 @@ name = "grarr"
version = "0.0.3"
dependencies = [
"chrono 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
"clippy 0.0.64 (registry+https://github.com/rust-lang/crates.io-index)",
"clippy 0.0.69 (git+https://github.com/Manishearth/rust-clippy?rev=rustup)",
"flate2 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"git-appraise 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"git2 0.4.3 (git+https://github.com/Nemo157/git2-rs?rev=packbuilder)",
"gravatar 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"gravatar 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"iron 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"logger 0.0.3 (git+https://github.com/Nemo157/logger?rev=personal_release)",
"lru_time_cache 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lru_time_cache 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"maud 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"maud-pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"maud_macros 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pulldown-cmark 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"router 0.1.1 (git+https://github.com/Nemo157/router?rev=reverse_priority)",
"rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
"typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -46,12 +47,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "0.5.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -65,13 +66,13 @@ dependencies = [
[[package]]
name = "clippy"
version = "0.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
version = "0.0.69"
source = "git+https://github.com/Manishearth/rust-clippy?rev=rustup#c3dc54df5d508eeeeb64da0274683c4b52f7d8c7"
dependencies = [
"quine-mc_cluskey 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -96,7 +97,7 @@ name = "cookie"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl 0.7.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -112,6 +113,15 @@ dependencies = [
]
[[package]]
name = "flate2"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"miniz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gcc"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -121,7 +131,7 @@ name = "gdi32-sys"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -135,8 +145,8 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"git2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_codegen 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_codegen 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntex 0.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -144,7 +154,7 @@ dependencies = [
[[package]]
name = "git2"
version = "0.4.3"
source = "git+https://github.com/Nemo157/git2-rs?rev=packbuilder#8d8fb7de861b14c72c7f76a41a4291ad4d52bb96"
source = "git+https://github.com/Nemo157/git2-rs?rev=packbuilder#a120f7b82ee35ba778a6e7d81fb9748fc46675d2"
dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -165,11 +175,11 @@ dependencies = [
[[package]]
name = "gravatar"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rust-crypto 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -195,8 +205,8 @@ dependencies = [
"language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl 0.7.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -227,7 +237,7 @@ dependencies = [
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
"plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -238,7 +248,7 @@ name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -259,25 +269,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libgit2-sys"
version = "0.4.3"
source = "git+https://github.com/Nemo157/git2-rs?rev=packbuilder#8d8fb7de861b14c72c7f76a41a4291ad4d52bb96"
source = "git+https://github.com/Nemo157/git2-rs?rev=packbuilder#a120f7b82ee35ba778a6e7d81fb9748fc46675d2"
dependencies = [
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"libssh2-sys 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.12 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -291,7 +296,7 @@ dependencies = [
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"libssh2-sys 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.12 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -311,7 +316,7 @@ dependencies = [
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.12 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -342,7 +347,7 @@ dependencies = [
[[package]]
name = "lru_time_cache"
version = "0.3.1"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -381,13 +386,22 @@ dependencies = [
]
[[package]]
name = "miniz-sys"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "modifier"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "nom"
version = "1.2.2"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -424,7 +438,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num_cpus"
version = "0.2.11"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -432,20 +446,20 @@ dependencies = [
[[package]]
name = "openssl"
version = "0.7.10"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys-extras 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.12 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys-extras 0.7.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "openssl-sys"
version = "0.7.10"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -457,12 +471,12 @@ dependencies = [
[[package]]
name = "openssl-sys-extras"
version = "0.7.10"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.7.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -537,7 +551,7 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -556,11 +570,11 @@ dependencies = [
[[package]]
name = "rust-crypto"
version = "0.2.35"
version = "0.2.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -589,17 +603,17 @@ name = "semver"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"nom 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"nom 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde"
version = "0.7.4"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_codegen"
version = "0.7.4"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aster 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -615,7 +629,7 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -662,7 +676,7 @@ version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -672,12 +686,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.1.28"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -766,7 +780,7 @@ name = "user32-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -784,12 +798,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.6"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]

Modified Cargo.toml

@@ -34,8 +34,9 @@ gravatar = "*"
maud = "*"
maud_macros = "*"
clippy = { version = "*", optional = true }
clippy = { version = "*", optional = true, git = "https://github.com/Manishearth/rust-clippy", rev = "rustup" }
rust-crypto = "*"
unicase = "*"
toml = "*"
rustc-serialize = "*"
flate2 = "*"

Modified src/handler/git_smart_http/upload_pack.rs

@@ -1,12 +1,14 @@
use handler::base::*;
use super::utils::*;
use std::io::{ Read, Write };
use std::collections::HashSet;
use iron::headers::{ CacheControl, CacheDirective, Vary, Pragma, Expires, HttpDate };
use iron::headers::{ CacheControl, CacheDirective, Vary, Pragma, Expires, HttpDate, ContentEncoding, Encoding };
use iron::modifiers::Header;
use unicase::UniCase;
use time;
use flate2::FlateReadExt;
use git2::{ self, Oid, Repository, Buf };
@@ -39,7 +41,21 @@ fn parse_request(req: &mut Request) -> Result<UploadPackRequest, Error> {
capabilities: Vec::new(),
done: false,
};
for line in req.body.pkt_lines() {
let encoding = if let Some(&ContentEncoding(ref encodings)) = req.headers.get() {
if encodings.len() != 1 {
return Err(Error::from("Can't handle multiple encodings"));
}
encodings[0].clone()
} else {
Encoding::Identity
};
let mut body = match encoding {
Encoding::Identity => Box::new(&mut req.body) as Box<Read>,
Encoding::Gzip => Box::new(try!((&mut req.body).gz_decode())) as Box<Read>,
Encoding::Deflate => Box::new((&mut req.body).deflate_decode()) as Box<Read>,
encoding => return Err(Error::from(format!("Can't handle encoding {}", encoding))),
};
for line in body.pkt_lines() {
let line = try!(line);
if line.len() < 4 { continue }
match &line[0..4] {
@@ -145,13 +161,16 @@ fn compute_response(context: &UploadPackContext, request: &UploadPackRequest) ->
}
}
fn build_pack(repository: &Repository, commits: Vec<Oid>) -> Result<Buf, Error> {
fn build_pack(repository: &Repository, commits: Vec<Oid>) -> Result<Vec<u8>, Error> {
let mut builder = try!(repository.packbuilder());
for id in commits {
try!(builder.insert_commit(id));
}
let mut buf = Buf::new();
try!(builder.write_buf(&mut buf, None));
let mut buf = Vec::new();
try!(builder.foreach(|object| {
buf.write_all(object).unwrap();
true
}));
Ok(buf)
}
@@ -178,11 +197,9 @@ impl Handler for UploadPack {
UploadPackResponse::Pack(commits) => {
let pack = itry!(build_pack(&context.repository, commits), status::InternalServerError);
println!("built {} byte pack", pack.len());
let mut response = vec![0; pack.len() + 8];
response[0..8].clone_from_slice(&[
b'0', b'0', b'0', b'8', b'N', b'A', b'K', b'\n',
]);
response[8..].clone_from_slice(&*pack);
let mut response = Vec::with_capacity(pack.len() + 8);
response.write_pkt_line("NAK");
response.write_all(&*pack);
Ok(Response::with((status::Ok, no_cache, response)))
},
}

Modified src/main.rs

@@ -30,6 +30,7 @@ extern crate walkdir;
// extern crate params;
extern crate toml;
extern crate rustc_serialize;
extern crate flate2;
#[macro_use]
mod macros;