mirror of https://github.com/v2ray/v2ray-core
timeout settings in http proxy
parent
5e7d413404
commit
30041041d3
|
@ -2,6 +2,7 @@ package http
|
||||||
|
|
||||||
// Config for HTTP proxy server.
|
// Config for HTTP proxy server.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Timeout int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientConfig for HTTP proxy client.
|
// ClientConfig for HTTP proxy client.
|
||||||
|
|
|
@ -12,11 +12,13 @@ import (
|
||||||
// UnmarshalJSON implements json.Unmarshaler
|
// UnmarshalJSON implements json.Unmarshaler
|
||||||
func (this *Config) UnmarshalJSON(data []byte) error {
|
func (this *Config) UnmarshalJSON(data []byte) error {
|
||||||
type JsonConfig struct {
|
type JsonConfig struct {
|
||||||
|
Timeout int `json:"timeout"`
|
||||||
}
|
}
|
||||||
jsonConfig := new(JsonConfig)
|
jsonConfig := new(JsonConfig)
|
||||||
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
if err := json.Unmarshal(data, jsonConfig); err != nil {
|
||||||
return errors.New("HTTP: Failed to parse config: " + err.Error())
|
return errors.New("HTTP: Failed to parse config: " + err.Error())
|
||||||
}
|
}
|
||||||
|
this.Timeout = jsonConfig.Timeout
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,8 @@ func parseHost(rawHost string, defaultPort v2net.Port) (v2net.Destination, error
|
||||||
|
|
||||||
func (this *Server) handleConnection(conn internet.Connection) {
|
func (this *Server) handleConnection(conn internet.Connection) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
reader := bufio.NewReader(conn)
|
timedReader := v2net.NewTimeOutReader(this.config.Timeout, conn)
|
||||||
|
reader := bufio.NewReader(timedReader)
|
||||||
|
|
||||||
request, err := http.ReadRequest(reader)
|
request, err := http.ReadRequest(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue