func (h *HTTP) Close() error {
	return h.conn.Close()
}
Close closes the connection
package obfs
import (
	"bytes"
	"fmt"
	"net"
	"net/url"
	"time"
	"github.com/sakeven/mika/protocols"
	"github.com/sakeven/mika/utils"
)
type HTTP struct {
	isServerSide bool
	readStart    bool
	writeStart   bool
	conn         protocols.Protocol
	uri          string
	host         string
}
func NewHTTP(conn protocols.Protocol, isServerSide bool) *HTTP {
	return &HTTP{
		conn:         conn,
		isServerSide: isServerSide,
	}
}
func (h *HTTP) SetURI(uri string) error {
	u, err := url.Parse(uri)
	if err != nil {
		return err
	}
	h.uri = u.RequestURI()
	h.host = u.Host
	return nil
}
func (h *HTTP) RemoteAddr() net.Addr {
	return h.conn.RemoteAddr()
}
const timeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
func (h *HTTP) Write(b []byte) (n int, err error) {
	if !h.writeStart {
		var content string
		if h.isServerSide {
			content = fmt.Sprintf(responseTemplate, server[0], time.Now().Format(timeFormat))
		} else {
			content = fmt.Sprintf(reqTemplate, h.uri, h.host, userAgent[0])
		}
		utils.Debugf("content %s", content)
		h.conn.Write(append([]byte(content), b...))
		h.writeStart = true
		return
	}
	return h.conn.Write(b)
}
func (h *HTTP) Read(b []byte) (n int, err error) {
	if !h.readStart {
		last3 := make([]byte, 3)
		for {
			n, err = h.conn.Read(b)
			if err != nil {
				return 0, err
			}
			i := bytes.Index(append(last3, b[:n]...), []byte("\r\n\r\n"))
			if i >= 0 {
				i = i + 1
				n = n - i
				copy(b, b[i:])
				break
			}
			copyLast3(last3, b[:n])
		}
		h.readStart = true
		return
	}
	return h.conn.Read(b)
}
func copyLast3(last3, b []byte) {
	n := len(b)
	copy(last3, []byte{0, 0, 0})
	if n > 0 {
		last3[2] = b[n-1]
	}
	if n-1 > 0 {
		last3[1] = b[n-2]
	}
	if n-2 > 0 {
		last3[0] = b[n-3]
	}
}