Пример #1
0
	"errors"
	"flag"
	"github.com/garyburd/twister/expvar"
	"github.com/garyburd/twister/server"
	"github.com/garyburd/twister/web"
	"io/ioutil"
	"log"
	"net"
	"net/url"
	"regexp"
	"strings"
)

var (
	responseLineRegexp = regexp.MustCompile("^HTTP/[0-9.]+ ([0-9]+) ")
	connectionCount    = expvar.NewInt("connections")
	readCount          = expvar.NewInt("reads")
)

func dial(urlString string) (net.Conn, *bufio.Reader, error) {
	u, err := url.Parse(urlString)
	if err != nil {
		return nil, nil, err
	}

	addr := u.Host
	if strings.LastIndex(addr, ":") <= strings.LastIndex(addr, "]") {
		if u.Scheme == "http" {
			addr = addr + ":80"
		} else {
			addr = addr + ":443"
Пример #2
0
package main

import (
	"flag"
	"github.com/garyburd/twister/expvar"
	"github.com/garyburd/twister/server"
	"github.com/garyburd/twister/web"
	"math/rand"
	"runtime"
	"strconv"
	"time"
)

var (
	msg             = []byte("hello")
	connectionCount = expvar.NewInt("connections")
	messageCount    = expvar.NewInt("messges")
)

func testHandler(req *web.Request) {
	connectionCount.Add(1)
	defer connectionCount.Add(-1)
	w := req.Respond(web.StatusOK, web.HeaderContentType, web.ContentTypeHTML)
	for {
		<-time.After(time.Duration(10e9 + 1e9*rand.Int63n(10)))
		_, err := w.Write(msg)
		if err != nil {
			return
		}
		if w, ok := w.(web.Flusher); ok {
			err = w.Flush()