-
-
Save titanous/7a32f1a655a27fcfba2921a643a9863f to your computer and use it in GitHub Desktop.
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
threads 1, 48 | |
workers 1 | |
persistent_timeout 9999999 | |
preload_app! |
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
require 'rack' | |
require 'rack-ssl-enforcer' | |
use Rack::SslEnforcer, except: '/heartbeat' | |
run Proc.new { |env| | |
path = Rack::Request.new(env).path | |
case path | |
when '/api' | |
['200', {'Content-Type' => 'text/plain'}, ['foo']] | |
when '/heartbeat' | |
['200', {'Content-Type' => 'text/plain'}, ['ok']] | |
else | |
['404', {'Content-Type' => 'text/plain'}, ['not found']] | |
end | |
} |
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
source 'https://rubygems.org' | |
gem 'puma', '~> 3.10.0' | |
gem 'rack-ssl-enforcer', path: '../rack-ssl-enforcer' | |
gem 'rack' |
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
PATH | |
remote: ../rack-ssl-enforcer | |
specs: | |
rack-ssl-enforcer (0.2.9) | |
GEM | |
remote: https://rubygems.org/ | |
specs: | |
puma (3.10.0) | |
rack (2.0.7) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
puma (~> 3.10.0) | |
rack | |
rack-ssl-enforcer! | |
BUNDLED WITH | |
1.13.6 |
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
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os" | |
) | |
func main() { | |
url := os.Args[1] | |
launch(1, url+"/heartbeat", "ok", 200) | |
launch(10, url+"/api", "foo", 200) | |
<-make(chan struct{}) | |
} | |
func launch(n int, url, expectedResult string, expectedStatus int) { | |
for i := 0; i < n; i++ { | |
go func() { | |
log.Fatal(request(url, expectedResult, expectedStatus)) | |
}() | |
} | |
} | |
var httpClient = http.Client{ | |
CheckRedirect: func(*http.Request, []*http.Request) error { | |
return http.ErrUseLastResponse | |
}, | |
} | |
func request(url, expectedResult string, expectedStatus int) error { | |
fmt.Println("start", url) | |
for { | |
req, _ := http.NewRequest("GET", url, nil) | |
if expectedResult == "foo" { | |
req.Header.Set("X-Forwarded-Proto", "https") | |
} | |
res, err := httpClient.Do(req) | |
if err != nil { | |
return err | |
} | |
body, err := ioutil.ReadAll(res.Body) | |
res.Body.Close() | |
if err != nil { | |
return err | |
} | |
if res.StatusCode != expectedStatus { | |
return fmt.Errorf("%s unexpected status %d, wanted %d", url, res.StatusCode, expectedStatus) | |
} | |
if res.StatusCode == 301 { | |
if res.Header.Get("Location") != expectedResult { | |
return fmt.Errorf("%s unexpected location %q, wanted %q", url, res.Header.Get("Location"), expectedResult) | |
} | |
} else { | |
if string(body) != expectedResult { | |
return fmt.Errorf("%s unexpected body %q, wanted %q", url, string(body), expectedResult) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment