Skip to content

Commit ce59f44

Browse files
Remove gzip on responses
In prod, nginx can do this for us with less hassle as we don't need to concern ourselves with streaming the response and locally it makes very little difference whether we send ~3 or ~10 MB for our largest query responses, as local networks are plenty fast.
1 parent a15b77f commit ce59f44

File tree

3 files changed

+3
-21
lines changed

3 files changed

+3
-21
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ headers = "0.2.1"
1818
http = "0.1.17"
1919
antidote = "1.0"
2020
chrono = "0.4"
21-
flate2 = "1.0.9"
2221
rmp-serde = "0.13.7"
2322
semver = "0.9"
2423
ring = "0.16.0"

site/src/server.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@ use std::cmp::Ordering;
1212
use std::collections::HashMap;
1313
use std::fmt;
1414
use std::fs::File;
15-
use std::io::{Read, Write};
15+
use std::io::Read;
1616
use std::net::SocketAddr;
1717
use std::path::Path;
1818
use std::str;
1919
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
2020
use std::sync::Arc;
2121

2222
use failure::Error;
23-
use flate2::write::GzEncoder;
24-
use flate2::Compression;
2523
use futures::{self, Future, Stream};
2624
use futures_cpupool::CpuPool;
2725
use headers::CacheControl;
2826
use headers::Header;
29-
use headers::{Authorization, ContentEncoding, ContentLength, ContentType};
27+
use headers::{Authorization, ContentLength, ContentType};
3028
use hyper::StatusCode;
3129
use log::{debug, error, info};
3230
use regex::Regex;
@@ -807,10 +805,6 @@ impl Server {
807805
if length > 25_000 {
808806
return Box::new(futures::future::err(ServerError(format!("too large"))));
809807
}
810-
let accepts_gzip = req
811-
.headers()
812-
.get(http::header::ACCEPT_ENCODING)
813-
.map_or(false, |e| e.to_str().unwrap().contains("gzip"));
814808
let data = self.data.clone();
815809
let gh_header = req.headers().get("X-Hub-Signature").cloned();
816810
let gh_header = gh_header.and_then(|g| g.to_str().ok().map(|s| s.to_owned()));
@@ -865,17 +859,7 @@ impl Server {
865859
.header_typed(ContentType::octet_stream())
866860
.header_typed(CacheControl::new().with_no_cache().with_no_store());
867861
let body = rmp_serde::to_vec_named(&result).unwrap();
868-
if accepts_gzip {
869-
let mut encoder = GzEncoder::new(Vec::new(), Compression::fast());
870-
encoder.write_all(&*body).unwrap();
871-
let body = encoder.finish().unwrap();
872-
response
873-
.header_typed(ContentEncoding::gzip())
874-
.body(hyper::Body::from(body))
875-
.unwrap()
876-
} else {
877-
response.body(hyper::Body::from(body)).unwrap()
878-
}
862+
response.body(hyper::Body::from(body)).unwrap()
879863
}
880864
Err(err) => http::Response::builder()
881865
.status(StatusCode::INTERNAL_SERVER_ERROR)

0 commit comments

Comments
 (0)