Skip to content

Instantly share code, notes, and snippets.

@wlhee wlhee/client.go
Created Nov 23, 2019

What would you like to do?
slow client
package main
import (
var (
url = flag.String("url", "", "URL")
transportBuffer = flag.Int("transport_buffer", 10, "transport buffer size in bytes used by HTTP client")
readBuffer = flag.Int("read_buffer", 1, "read buffer size in bytes used for reading bytes from the trasport buffer")
readInterval = flag.Duration("read_interval", time.Second, "interval to read from the transport buffer into the read buffer")
func main() {
fmt.Printf("URL: %s\ntransport_buffer: %d\nread_buffer:%d\nread_interval: %v\n", *url, *transportBuffer, *readBuffer, *readInterval)
transport := &http.Transport{
ReadBufferSize: *transportBuffer,
client := &http.Client{Transport: transport}
response, err := client.Get(*url)
if err != nil {
fmt.Printf("%v\n", err)
defer response.Body.Close()
for k, v := range response.Header {
fmt.Printf("%s:%s\n", k, v)
buffer := make([]byte, *readBuffer)
for {
n, err := response.Body.Read(buffer)
if err != nil {
fmt.Printf("Read error: %v\n", err)
fmt.Printf("Read %d bytes: %s\n", n, string(buffer))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.