Skip to content

Instantly share code, notes, and snippets.

@titanous

titanous/Gemfile Secret

Last active October 7, 2019 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save titanous/7a32f1a655a27fcfba2921a643a9863f to your computer and use it in GitHub Desktop.
Save titanous/7a32f1a655a27fcfba2921a643a9863f to your computer and use it in GitHub Desktop.
threads 1, 48
workers 1
persistent_timeout 9999999
preload_app!
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
}
source 'https://rubygems.org'
gem 'puma', '~> 3.10.0'
gem 'rack-ssl-enforcer', path: '../rack-ssl-enforcer'
gem 'rack'
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
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