-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed significant bug where proxy wouldn;t work with virtual host ser…
…vers like heroku
- Loading branch information
Martin Buhr
committed
Jul 30, 2014
1 parent
9c08218
commit 82695eb
Showing
8 changed files
with
122 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "Tyk Test API", | ||
"api_id": "1", | ||
"org_id": "default", | ||
"definition": { | ||
"location": "", | ||
"key": "" | ||
}, | ||
"use_keyless": true, | ||
"auth": { | ||
"auth_header_name": "" | ||
}, | ||
"version_data": { | ||
"not_versioned": true, | ||
"versions": { | ||
"Default": { | ||
"name": "Default", | ||
"expires": "3000-01-02 15:04", | ||
"paths": { | ||
"ignored": [], | ||
"white_list": [], | ||
"black_list": [] | ||
} | ||
} | ||
} | ||
}, | ||
"proxy": { | ||
"listen_path": "/quickstart/", | ||
"target_url": "http://httpbin.org/", | ||
"strip_listen_path": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"listen_port": 5000, | ||
"secret": "352d20ee67be67f6340b4c0605b044b7", | ||
"use_db_app_configs": false, | ||
"template_path": "templates", | ||
"app_path": "apps", | ||
"storage": { | ||
"type": "redis", | ||
"host": "localhost", | ||
"port": 6379, | ||
"username": "user", | ||
"password": "test" | ||
}, | ||
"enable_analytics": false, | ||
"analytics_config": { | ||
"type": "csv", | ||
"csv_dir": "/tmp/", | ||
"purge_delay": 10, | ||
"mongo_url": "", | ||
"mongo_db_name": "", | ||
"mongo_collection": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2011 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// HTTP reverse proxy handler | ||
|
||
package main | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
"net/http/httputil" | ||
) | ||
|
||
|
||
// Copied form the original stdlib for ReverseProxy | ||
func singleJoiningSlash(a, b string) string { | ||
aslash := strings.HasSuffix(a, "/") | ||
bslash := strings.HasPrefix(b, "/") | ||
switch { | ||
case aslash && bslash: | ||
return a + b[1:] | ||
case !aslash && !bslash: | ||
return a + "/" + b | ||
} | ||
return a + b | ||
} | ||
|
||
// TykNewSingleHostReverseProxy returns a new ReverseProxy that rewrites | ||
// URLs to the scheme, host, and base path provided in target. If the | ||
// target's path is "/base" and the incoming request was for "/dir", | ||
// the target request will be for /base/dir. This version modifies the | ||
// stdlib version by also setting the host to the target, this allows | ||
// us to work with heroku and other such providers | ||
func TykNewSingleHostReverseProxy(target *url.URL) *httputil.ReverseProxy { | ||
targetQuery := target.RawQuery | ||
director := func(req *http.Request) { | ||
req.URL.Scheme = target.Scheme | ||
req.URL.Host = target.Host | ||
req.URL.Path = singleJoiningSlash(target.Path, req.URL.Path) | ||
req.Host = target.Host | ||
if targetQuery == "" || req.URL.RawQuery == "" { | ||
req.URL.RawQuery = targetQuery + req.URL.RawQuery | ||
} else { | ||
req.URL.RawQuery = targetQuery + "&" + req.URL.RawQuery | ||
} | ||
} | ||
return &httputil.ReverseProxy{Director: director} | ||
} | ||
|