Skip to content

Commit

Permalink
Merge branch 'develop', version 0.7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Jul 28, 2013
2 parents 29b0ed4 + f9f9edb commit 34a790b
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 138 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.7.6 (2013-07-28)
* Fix bug for close connection response with no body
* Fix response not keep alive by default
* Always try parent proxy upon DNS/connection error
* Do not take special handling on log with debug option
* Add proxy status statistics in debug code

0.7.5 (2013-07-25)
* Fix crash on IPv6 client authentication
* Provide ARMv6 binary
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

COW 是一个利用二级代理自动化穿越防火墙的 HTTP 代理服务器。它能自动检测被墙网站,仅对这些网站使用二级代理。

当前版本:0.7.5 [CHANGELOG](CHANGELOG)
当前版本:0.7.6 [CHANGELOG](CHANGELOG)
[![Build Status](https://travis-ci.org/cyfdecyf/cow.png?branch=master)](https://travis-ci.org/cyfdecyf/cow)

**欢迎在 develop branch 进行开发并发送 pull request :)**
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const (
version = "0.7.5"
version = "0.7.6"
defaultListenAddr = "127.0.0.1:7777"
)

Expand Down
41 changes: 28 additions & 13 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ import (
"time"
)

const (
statusCodeContinue = 100
)

const (
statusBadReq = "400 Bad Request"
statusExpectFailed = "417 Expectation Failed"
statusRequestTimeout = "408 Request Time-out"
)

type Header struct {
ContLen int64
KeepAlive time.Duration
Expand Down Expand Up @@ -127,15 +137,6 @@ func (r *Request) proxyRequestLine() []byte {
return r.raw.Bytes()[0:r.reqLnStart]
}

const (
statusCodeContinue = 100
)

const (
statusBadReq = "400 Bad Request"
statusExpectFailed = "417 Expectation Failed"
)

type Response struct {
Status int
Reason []byte
Expand All @@ -146,7 +147,7 @@ type Response struct {
rawByte []byte
}

var zeroResponse = Response{}
var zeroResponse = Response{Header: Header{ConnectionKeepAlive: true}}

func (rp *Response) reset() {
b := rp.rawByte
Expand Down Expand Up @@ -447,15 +448,17 @@ func (h *Header) parseHeader(reader *bufio.Reader, raw *bytes.Buffer, url *URL)
func parseRequest(c *clientConn, r *Request) (err error) {
var s []byte
reader := c.bufRd
setConnReadTimeout(c, clientConnTimeout, "parseRequest")
// make actual timeout a little longer than keep-alive value sent to client
setConnReadTimeout(c.Conn,
clientConnTimeout+time.Duration(c.timeoutCnt)*time.Second, "parseRequest")
// parse request line
if s, err = reader.ReadSlice('\n'); err != nil {
if isErrTimeout(err) {
return errClientTimeout
}
return err
}
unsetConnReadTimeout(c, "parseRequest")
unsetConnReadTimeout(c.Conn, "parseRequest")
// debug.Printf("Request line %s", s)

r.reset()
Expand Down Expand Up @@ -599,8 +602,20 @@ func parseResponse(sv *serverConn, r *Request, rp *Response) (err error) {
// Connection close, no content length specification
// Use chunked encoding to pass content back to client
if !rp.ConnectionKeepAlive && !rp.Chunking && rp.ContLen == -1 {
rp.raw.WriteString("Transfer-Encoding: chunked\r\n")
if rp.hasBody(r.Method) {
debug.Println("add chunked encoding to close connection response", r, rp)
rp.raw.WriteString("Transfer-Encoding: chunked\r\n")
} else {
debug.Println("add content-length 0 to close connection response", r, rp)
rp.raw.WriteString("Content-Length: 0\r\n")
}
}
// Check for invalid response
if !rp.hasBody(r.Method) && (rp.Chunking || rp.ContLen != -1) {
errl.Printf("response has no body, but with chunked/content-length set\n%s",
rp.Verbose())
}

// Whether COW should respond with keep-alive depends on client request,
// not server response.
if r.ConnectionKeepAlive {
Expand Down
2 changes: 1 addition & 1 deletion install-cow.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

version=0.7.5
version=0.7.6

arch=`uname -m`
case $arch in
Expand Down
8 changes: 2 additions & 6 deletions log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

// This trick is learnt from a post by Rob Pike
// This logging trick is learnt from a post by Rob Pike
// https://groups.google.com/d/msg/golang-nuts/gU7oQGoCkmg/j3nNxuS2O_sJ

import (
Expand Down Expand Up @@ -49,11 +49,7 @@ func init() {

func initLog() {
logFile = os.Stdout
if bool(debug) && !isWindows {
// On windows, we don't know if the terminal supports ANSI color, so
// does not turn color by default in debug mode
colorize = true
} else if config.LogFile != "" {
if config.LogFile != "" {
if f, err := os.OpenFile(expandTilde(config.LogFile),
os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600); err != nil {
fmt.Printf("Can't open log file, logging to stdout: %v\n", err)
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func main() {
initSiteStat()
initPAC() // initPAC uses siteStat, so must init after site stat

initStat()

if len(parentProxy) == 0 {
info.Println("no parent proxy server, can't handle blocked sites")
} else {
Expand Down
7 changes: 3 additions & 4 deletions parent_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/base64"
"encoding/binary"
"errors"
"fmt"
ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
"io"
"math/rand"
Expand Down Expand Up @@ -81,11 +80,11 @@ func printParentProxy() {
for _, pp := range parentProxy {
switch pc := pp.proxyConnector.(type) {
case *shadowsocksParent:
fmt.Println("\tshadowsocks: ", pc.server)
debug.Println("\tshadowsocks: ", pc.server)
case *httpParent:
fmt.Println("\thttp parent: ", pc.server)
debug.Println("\thttp parent: ", pc.server)
case socksParent:
fmt.Println("\tsocks parent: ", pc.server)
debug.Println("\tsocks parent: ", pc.server)
}
}
}
Expand Down
Loading

0 comments on commit 34a790b

Please sign in to comment.