informational logs

pull/168/head
v2ray 2016-06-02 00:57:08 +02:00
parent 9713bf9adf
commit 6ce7b1d532
2 changed files with 22 additions and 18 deletions

View File

@ -68,7 +68,7 @@ func (this *DefaultDispatcher) DispatchToOutbound(destination v2net.Destination)
func (this *DefaultDispatcher) FilterPacketAndDispatch(destination v2net.Destination, link ray.OutboundRay, dispatcher proxy.OutboundHandler) { func (this *DefaultDispatcher) FilterPacketAndDispatch(destination v2net.Destination, link ray.OutboundRay, dispatcher proxy.OutboundHandler) {
payload, err := link.OutboundInput().Read() payload, err := link.OutboundInput().Read()
if err != nil { if err != nil {
log.Info("DefaultDispatcher: No payload to dispatch, stopping now.") log.Info("DefaultDispatcher: No payload towards ", destination, ", stopping now.")
link.OutboundInput().Release() link.OutboundInput().Release()
link.OutboundOutput().Release() link.OutboundOutput().Release()
return return

View File

@ -110,10 +110,10 @@ func (this *Server) handleConnection(conn *hub.Connection) {
request, err := http.ReadRequest(reader) request, err := http.ReadRequest(reader)
if err != nil { if err != nil {
log.Warning("Failed to read http request: ", err) log.Warning("HTTP: Failed to read http request: ", err)
return return
} }
log.Info("Request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]") log.Info("HTTP: Request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]")
defaultPort := v2net.Port(80) defaultPort := v2net.Port(80)
if strings.ToLower(request.URL.Scheme) == "https" { if strings.ToLower(request.URL.Scheme) == "https" {
defaultPort = v2net.Port(443) defaultPort = v2net.Port(443)
@ -124,7 +124,7 @@ func (this *Server) handleConnection(conn *hub.Connection) {
} }
dest, err := parseHost(host, defaultPort) dest, err := parseHost(host, defaultPort)
if err != nil { if err != nil {
log.Warning("Malformed proxy host (", host, "): ", err) log.Warning("HTTP: Malformed proxy host (", host, "): ", err)
return return
} }
if strings.ToUpper(request.Method) == "CONNECT" { if strings.ToUpper(request.Method) == "CONNECT" {
@ -205,13 +205,12 @@ func StripHopByHopHeaders(request *http.Request) {
} }
} }
func (this *Server) handlePlainHTTP(request *http.Request, dest v2net.Destination, reader *bufio.Reader, writer io.Writer) { func (this *Server) GenerateResponse(statusCode int, status string) *http.Response {
if len(request.URL.Host) <= 0 {
hdr := http.Header(make(map[string][]string)) hdr := http.Header(make(map[string][]string))
hdr.Set("Connection", "close") hdr.Set("Connection", "close")
response := &http.Response{ return &http.Response{
Status: "400 Bad Request", Status: status,
StatusCode: 400, StatusCode: statusCode,
Proto: "HTTP/1.1", Proto: "HTTP/1.1",
ProtoMajor: 1, ProtoMajor: 1,
ProtoMinor: 1, ProtoMinor: 1,
@ -220,6 +219,11 @@ func (this *Server) handlePlainHTTP(request *http.Request, dest v2net.Destinatio
ContentLength: 0, ContentLength: 0,
Close: false, Close: false,
} }
}
func (this *Server) handlePlainHTTP(request *http.Request, dest v2net.Destination, reader *bufio.Reader, writer io.Writer) {
if len(request.URL.Host) <= 0 {
response := this.GenerateResponse(400, "Bad Request")
buffer := alloc.NewSmallBuffer().Clear() buffer := alloc.NewSmallBuffer().Clear()
response.Write(buffer) response.Write(buffer)
@ -255,7 +259,7 @@ func (this *Server) handlePlainHTTP(request *http.Request, dest v2net.Destinatio
response, err := http.ReadResponse(responseReader, request) response, err := http.ReadResponse(responseReader, request)
if err != nil { if err != nil {
log.Warning("HTTP: Failed to read response: ", err) log.Warning("HTTP: Failed to read response: ", err)
return response = this.GenerateResponse(503, "Service Unavailable")
} }
responseWriter := v2io.NewBufferedWriter(writer) responseWriter := v2io.NewBufferedWriter(writer)
err = response.Write(responseWriter) err = response.Write(responseWriter)