1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-13 21:56:59 -05:00

timeout settings in http proxy

This commit is contained in:
v2ray 2016-07-10 15:34:14 +02:00
parent 5e7d413404
commit 30041041d3
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 5 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package http
// Config for HTTP proxy server.
type Config struct {
Timeout int
}
// ClientConfig for HTTP proxy client.

View File

@ -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
}

View File

@ -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 {