OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package webpagereplay | 5 package webpagereplay |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "fmt" | 9 "fmt" |
10 "io" | 10 "io" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 if req.URL.Path == "/web-page-replay-command-exit" { | 55 if req.URL.Path == "/web-page-replay-command-exit" { |
56 log.Printf("Shutting down. Received /web-page-replay-command-exi
t") | 56 log.Printf("Shutting down. Received /web-page-replay-command-exi
t") |
57 RemoveRoot() | 57 RemoveRoot() |
58 os.Exit(0) | 58 os.Exit(0) |
59 return | 59 return |
60 } | 60 } |
61 fixupRequestURL(req, proxy.scheme) | 61 fixupRequestURL(req, proxy.scheme) |
62 logf := makeLogger(req) | 62 logf := makeLogger(req) |
63 | 63 |
64 // Lookup the response in the archive. | 64 // Lookup the response in the archive. |
65 » _, storedResp, _, err := proxy.a.FindRequest(req, proxy.scheme) | 65 » _, storedResp, err := proxy.a.FindRequest(req, proxy.scheme) |
66 if err != nil { | 66 if err != nil { |
67 logf("couldn't find matching request: %v", err) | 67 logf("couldn't find matching request: %v", err) |
68 w.WriteHeader(http.StatusNotFound) | 68 w.WriteHeader(http.StatusNotFound) |
69 return | 69 return |
70 } | 70 } |
71 defer storedResp.Body.Close() | 71 defer storedResp.Body.Close() |
72 | 72 |
73 // Check if the stored Content-Encoding matches an encoding allowed by t
he client. | 73 // Check if the stored Content-Encoding matches an encoding allowed by t
he client. |
74 // If not, transform the response body to match the client's Accept-Enco
ding. | 74 // If not, transform the response body to match the client's Accept-Enco
ding. |
75 clientAE := strings.ToLower(req.Header.Get("Accept-Encoding")) | 75 clientAE := strings.ToLower(req.Header.Get("Accept-Encoding")) |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // Restore the req/resp body before archiving. | 202 // Restore the req/resp body before archiving. |
203 // The req body was consumed by RoundTrip, and the resp body was consume
d by the above io.Copy. | 203 // The req body was consumed by RoundTrip, and the resp body was consume
d by the above io.Copy. |
204 if req.Body != nil { | 204 if req.Body != nil { |
205 req.Body = ioutil.NopCloser(bytes.NewReader(requestBody)) | 205 req.Body = ioutil.NopCloser(bytes.NewReader(requestBody)) |
206 } | 206 } |
207 resp.Body = ioutil.NopCloser(bytes.NewReader(responseBody)) | 207 resp.Body = ioutil.NopCloser(bytes.NewReader(responseBody)) |
208 if err := proxy.a.RecordRequest(proxy.scheme, req, resp); err != nil { | 208 if err := proxy.a.RecordRequest(proxy.scheme, req, resp); err != nil { |
209 logf("failed recording request: %v", err) | 209 logf("failed recording request: %v", err) |
210 } | 210 } |
211 } | 211 } |
OLD | NEW |