This file contains hidden or 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" | |
| "net/http" | |
| "net/http/pprof" | |
| "strings" | |
| ) | |
| func handler(w http.ResponseWriter, r *http.Request) { |
This file contains hidden or 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
| type Cache struct { | |
| kv map[string]*bufio.Reader | |
| http.RoundTripper | |
| } | |
| func (c *Cache) RoundTrip(req *http.Request) (*http.Response, error) { | |
| if req.Method != "GET" { | |
| return c.RoundTrip(req) | |
| } |
This file contains hidden or 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
| type RoundTripper interface { | |
| RoundTrip(*Request) (*Response, error) | |
| } |
This file contains hidden or 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
| // http.Client - comments removed | |
| type Client struct { | |
| Transport RoundTripper | |
| CheckRedirect func(req *Request, via []*Request) error | |
| Jar CookieJar | |
| Timeout time.Duration | |
| } |
This file contains hidden or 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
| c := &http.Client{ | |
| Transport: &http.Transport{ | |
| Dial: (&net.Dialer{ | |
| Timeout: 30 * time.Second, | |
| KeepAlive: 30 * time.Second, | |
| }).Dial, | |
| TLSHandshakeTimeout: 10 * time.Second, | |
| ResponseHeaderTimeout: 10 * time.Second, | |
| ExpectContinueTimeout: 1 * time.Second, | |
| }, |
This file contains hidden or 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
| resp, err := http.Get("http://example.com/") |
This file contains hidden or 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
| // Retry - http client with retry support | |
| type Retry struct { | |
| http.RoundTripper | |
| } | |
| // Naive Retry - every 2 seconds | |
| func (r *Retry) RoundTrip(req *http.Request) (*http.Response, error) { | |
| for { | |
| resp, err := r.RoundTripper.RoundTrip(req) |
This file contains hidden or 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
| type Retry struct { | |
| http.RoundTripper | |
| } | |
| func (r *Retry) RoundTrip(req *http.Request) (*http.Response, error) { | |
| for { | |
| log.Printf("retry: doing request %s\n", req.URL) | |
| resp, err := r.RoundTripper.RoundTrip(req) | |
| if err == nil && resp.StatusCode < 500 { |
This file contains hidden or 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
| # old mac | |
| sudo ipfw pipe 1 config bw 300kbit/s; | |
| sudo ipfw add pipe 1 dst-ip 0.0.0.0/0; | |
| # to reset: | |
| sudo ipfw flush | |
| # | |
| dnctl pipe 1 config bw 10Kbit/s delay 300 | |
| echo "dummynet out proto tcp from any to example.com pipe 1" |pfctl -f - |
This file contains hidden or 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
| counter http_requests_total by method,status | |
| counter http_requests_time_seconds by bucket, method, status | |
| #log_format main '$realip_remote_addr "$remote_addr" "environment" ' | |
| # '- $remote_user ' | |
| # '[$time_local] "$request_id" "$cookie_PHPSESSID" ' | |
| # '"$request" $status $bytes_sent "$http_referer" ' | |
| # '"$http_user_agent" "-" ($request_time)'; | |
| /(?P<local>\d+(\.\d+){3})\s+/ + # local ip |