summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Schickendantz <[email protected]>2022-08-18 20:45:09 -0400
committerJeroen Schickendantz <[email protected]>2022-08-18 20:45:09 -0400
commit24fd73313e767c736f5b5f427391ff48bd07847c (patch)
treefa1708e6b0b99cca47b2baad153c8548a7b80d87
parent64614ce713b03025204da4ca528c5d561a2fc57f (diff)
Force No Compression
Force http-compression off by: Sending header "Accept-Encoding: identity" in request. Checking header "Content-Encoding" in response.
-rw-r--r--lgc/lgc.go26
-rw-r--r--rpm/rpm.go8
2 files changed, 33 insertions, 1 deletions
diff --git a/lgc/lgc.go b/lgc/lgc.go
index 07ce672..7b640e4 100644
--- a/lgc/lgc.go
+++ b/lgc/lgc.go
@@ -306,6 +306,9 @@ func (lgd *LoadGeneratingConnectionDownload) doDownload(ctx context.Context) {
return
}
+ // Used to disable compression
+ request.Header.Set("Accept-Encoding", "identity")
+
lgd.downloadStartTime = time.Now()
lgd.lastIntervalEnd = 0
@@ -313,6 +316,13 @@ func (lgd *LoadGeneratingConnectionDownload) doDownload(ctx context.Context) {
lgd.valid = false
return
}
+
+ // Header.Get returns "" when not set
+ if get.Header.Get("Content-Encoding") != "" {
+ lgd.valid = false
+ fmt.Printf("Content-Encoding header was set (compression not allowed)")
+ return
+ }
cr := &countingReader{n: &lgd.downloaded, ctx: ctx, readable: get.Body}
_, _ = io.Copy(ioutil.Discard, cr)
get.Body.Close()
@@ -379,15 +389,29 @@ func (lgu *LoadGeneratingConnectionUpload) doUpload(ctx context.Context) bool {
lgu.uploaded = 0
s := &syntheticCountingReader{n: &lgu.uploaded, ctx: ctx}
var resp *http.Response = nil
+ var request *http.Request = nil
var err error
+ if request, err = http.NewRequest(
+ "POST",
+ lgu.Path,
+ s,
+ ); err != nil {
+ lgu.valid = false
+ return false
+ }
+
+ // Used to disable compression
+ request.Header.Set("Accept-Encoding", "identity")
+
lgu.uploadStartTime = time.Now()
lgu.lastIntervalEnd = 0
- if resp, err = lgu.client.Post(lgu.Path, "application/octet-stream", s); err != nil {
+ if resp, err = lgu.client.Do(request); err != nil {
lgu.valid = false
return false
}
+
resp.Body.Close()
if debug.IsDebug(lgu.debug) {
fmt.Printf("Ending a load-generating upload.\n")
diff --git a/rpm/rpm.go b/rpm/rpm.go
index 607cffa..3b32273 100644
--- a/rpm/rpm.go
+++ b/rpm/rpm.go
@@ -127,11 +127,19 @@ func Probe(
return err
}
+ // Used to disable compression
+ probe_req.Header.Set("Accept-Encoding", "identity")
+
probe_resp, err := client.Do(probe_req)
if err != nil {
return err
}
+ // Header.Get returns "" when not set
+ if probe_resp.Header.Get("Content-Encoding") != "" {
+ return fmt.Errorf("Content-Encoding header was set (compression not allowed)")
+ }
+
// TODO: Make this interruptable somehow by using _ctx_.
_, err = io.ReadAll(probe_resp.Body)
if err != nil {