From 30041041d3f87df49daa3008ff4d4cd080e54aa5 Mon Sep 17 00:00:00 2001 From: v2ray Date: Sun, 10 Jul 2016 15:34:14 +0200 Subject: [PATCH] timeout settings in http proxy --- proxy/http/config.go | 1 + proxy/http/config_json.go | 2 ++ proxy/http/server.go | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/proxy/http/config.go b/proxy/http/config.go index c6d70d99..8df9260a 100644 --- a/proxy/http/config.go +++ b/proxy/http/config.go @@ -2,6 +2,7 @@ package http // Config for HTTP proxy server. type Config struct { + Timeout int } // ClientConfig for HTTP proxy client. diff --git a/proxy/http/config_json.go b/proxy/http/config_json.go index 5071ae38..bc8e0de9 100644 --- a/proxy/http/config_json.go +++ b/proxy/http/config_json.go @@ -12,11 +12,13 @@ import ( // UnmarshalJSON implements json.Unmarshaler func (this *Config) UnmarshalJSON(data []byte) error { type JsonConfig struct { + Timeout int `json:"timeout"` } jsonConfig := new(JsonConfig) if err := json.Unmarshal(data, jsonConfig); err != nil { return errors.New("HTTP: Failed to parse config: " + err.Error()) } + this.Timeout = jsonConfig.Timeout return nil } diff --git a/proxy/http/server.go b/proxy/http/server.go index c3cd1bef..41fb7a10 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -95,7 +95,8 @@ func parseHost(rawHost string, defaultPort v2net.Port) (v2net.Destination, error func (this *Server) handleConnection(conn internet.Connection) { defer conn.Close() - reader := bufio.NewReader(conn) + timedReader := v2net.NewTimeOutReader(this.config.Timeout, conn) + reader := bufio.NewReader(timedReader) request, err := http.ReadRequest(reader) if err != nil {