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

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: Added integration test to Chrome Proxy to verify direct connection on remote site timeout 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
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 // delay longer than 30s test failure threshold to any request coming from the
sclittle 2016/08/09 21:31:32 nit: looking at the rest of the file, it looks lik
Robert Ogden 2016/08/09 21:56:22 Done.
89 // proxy, but respond 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 client, will then use direct instead
sclittle 2016/08/09 21:31:32 nit: Could you capitalize the first word in this s
Robert Ogden 2016/08/09 21:56:22 Done.
93 time.Sleep(60 * time.Second);
sclittle 2016/08/09 21:31:32 What is actually causing the bypass? Are you sure
Robert Ogden 2016/08/09 21:56:22 Done.
94 w.Write([]byte("You are proxy"));
95 } else {
96 w.Write([]byte("You are direct"));
97 }
98 }
99
85 type override struct { 100 type override struct {
86 status int 101 status int
87 header http.Header 102 header http.Header
88 body io.Reader 103 body io.Reader
89 } 104 }
90 105
91 // parseOverrideQuery parses the queries in r and returns an override. 106 // parseOverrideQuery parses the queries in r and returns an override.
92 // It supports the following queries: 107 // It supports the following queries:
93 // "respStatus": an integer to override response status code; 108 // "respStatus": an integer to override response status code;
94 // "respHeader": base64 encoded JSON data to override the response headers; 109 // "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 169 return false, nil
155 } 170 }
156 171
157 func writeFromFile(w io.Writer, filename string) (int64, error) { 172 func writeFromFile(w io.Writer, filename string) (int64, error) {
158 f, err := os.Open(filename) 173 f, err := os.Open(filename)
159 if err != nil { 174 if err != nil {
160 return 0, err 175 return 0, err
161 } 176 }
162 return io.Copy(w, f) 177 return io.Copy(w, f)
163 } 178 }
OLDNEW
« tools/chrome_proxy/testserver/app.yaml ('K') | « tools/chrome_proxy/testserver/app.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698