Browse Source

timeout settings in http proxy

v2ray 9 years ago
parent
commit
30041041d3
3 changed files with 5 additions and 1 deletions
  1. 1 0
      proxy/http/config.go
  2. 2 0
      proxy/http/config_json.go
  3. 2 1
      proxy/http/server.go

+ 1 - 0
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.

+ 2 - 0
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
 }

+ 2 - 1
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 {