Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tools/chrome_proxy/testserver/server.go

Issue 2206363002: Added integration test to Chrome Proxy to verify direct connection on remote site timeout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated timing to server=90s and test=120s Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/chrome_proxy/testserver/app.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // Test server to facilitate the data reduction proxy Telemetry tests. 5 // Test server to facilitate the data reduction proxy Telemetry tests.
6 // 6 //
7 // The server runs at http://chromeproxy-test.appspot.com/. Please contact 7 // The server runs at http://chromeproxy-test.appspot.com/. Please contact
8 // people in OWNERS for server issues. 8 // people in OWNERS for server issues.
9 // 9 //
10 // For running an AppEngine Go server, see: 10 // For running an AppEngine Go server, see:
(...skipping 17 matching lines...) Expand all
28 import ( 28 import (
29 "bytes" 29 "bytes"
30 "encoding/base64" 30 "encoding/base64"
31 "encoding/json" 31 "encoding/json"
32 "errors" 32 "errors"
33 "fmt" 33 "fmt"
34 "io" 34 "io"
35 "net/http" 35 "net/http"
36 "os" 36 "os"
37 "strconv" 37 "strconv"
38 "strings"
39 "time"
38 ) 40 )
39 41
40 func init() { 42 func init() {
41 http.HandleFunc("/requestHeader", requestHeader) 43 http.HandleFunc("/requestHeader", requestHeader)
42 http.HandleFunc("/resource", resource) 44 http.HandleFunc("/resource", resource)
43 http.HandleFunc("/default", defaultResponse) 45 http.HandleFunc("/default", defaultResponse)
46 http.HandleFunc("/blackhole", blackholeProxy)
44 } 47 }
45 48
46 // requestHander returns request headers in response body as text. 49 // requestHander returns request headers in response body as text.
47 func requestHeader(w http.ResponseWriter, r *http.Request) { 50 func requestHeader(w http.ResponseWriter, r *http.Request) {
48 r.Header.Write(w) 51 r.Header.Write(w)
49 } 52 }
50 53
51 // resource returns the content of a data file specified by "r=" query as the re sponse body. 54 // resource returns the content of a data file specified by "r=" query as the re sponse body.
52 // The response could be overridden by request queries. 55 // The response could be overridden by request queries.
53 // See parseOverrideQuery. 56 // See parseOverrideQuery.
(...skipping 21 matching lines...) Expand all
75 func defaultResponse(w http.ResponseWriter, r *http.Request) { 78 func defaultResponse(w http.ResponseWriter, r *http.Request) {
76 wroteBody, err := applyOverride(w, r) 79 wroteBody, err := applyOverride(w, r)
77 if err != nil { 80 if err != nil {
78 return 81 return
79 } 82 }
80 if !wroteBody { 83 if !wroteBody {
81 w.Write([]byte("ok")) 84 w.Write([]byte("ok"))
82 } 85 }
83 } 86 }
84 87
88 // blackholePoxy delays 90 seconds for proxied responses, in order to test if
89 // the proxy will timeout on the site. Responds immediately to any other request .
90 func blackholeProxy(w http.ResponseWriter, r *http.Request) {
91 if strings.Contains(r.Header.Get("via"), "Chrome-Compression-Proxy") {
92 // Causes timeout on proxy, will then send BLOCK_ONCE.
93 // Appspot will 502 traffic at 120 seconds with no response.
94 time.Sleep(90 * time.Second);
95 w.Write([]byte("You are proxy"));
96 } else {
97 w.Write([]byte("You are direct"));
98 }
99 }
100
85 type override struct { 101 type override struct {
86 status int 102 status int
87 header http.Header 103 header http.Header
88 body io.Reader 104 body io.Reader
89 } 105 }
90 106
91 // parseOverrideQuery parses the queries in r and returns an override. 107 // parseOverrideQuery parses the queries in r and returns an override.
92 // It supports the following queries: 108 // It supports the following queries:
93 // "respStatus": an integer to override response status code; 109 // "respStatus": an integer to override response status code;
94 // "respHeader": base64 encoded JSON data to override the response headers; 110 // "respHeader": base64 encoded JSON data to override the response headers;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return false, nil 170 return false, nil
155 } 171 }
156 172
157 func writeFromFile(w io.Writer, filename string) (int64, error) { 173 func writeFromFile(w io.Writer, filename string) (int64, error) {
158 f, err := os.Open(filename) 174 f, err := os.Open(filename)
159 if err != nil { 175 if err != nil {
160 return 0, err 176 return 0, err
161 } 177 }
162 return io.Copy(w, f) 178 return io.Copy(w, f)
163 } 179 }
OLDNEW
« no previous file with comments | « tools/chrome_proxy/testserver/app.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698