private void OnHttpDecode(ISession session, PipeStream pstream) { START: if (mRequest == null) { mRequest = mServer.CreateRequest(session); //new HttpRequest(session, mServer); } if (mRequest.Read(pstream) == LoadedState.Completed) { int length = mRequest.Length; if (mRequest.Method == HttpParse.POST_TAG || mRequest.Method == HttpParse.GET_TAG || mRequest.Method == HttpParse.PUT_TAG || mRequest.Method == HttpParse.DELETE_TAG ) { Completed?.Invoke(this, mCompletedArgs.SetInfo(session, mRequest)); } else { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, "{0} {1} {2} not support", session.RemoteEndPoint, mRequest.Method, mRequest.Url); } HttpToken token = (HttpToken)session.Tag; token.KeepAlive = false; NotSupportResult notSupport = new NotSupportResult("Method:" + mRequest.Method + " not supper"); mRequest.CreateResponse().Result(notSupport); } mRequest = null; if (pstream.Length == 0) { return; } goto START; } else { if ((int)mRequest.State < (int)LoadedState.Header && pstream.Length > 1024 * 4) { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, "{0} http header too long!", session.RemoteEndPoint); } session.Dispose(); } else if (mRequest.Length > mServerConfig.MaxBodyLength) { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, "{0} http body too long!", session.RemoteEndPoint); } session.Dispose(); return; } return; } }
private void OnHttpDecode(ISession session, PipeStream pstream) { if (mRequest == null) { mRequest = mServer.CreateRequest(session); } if (mRequest.Read(pstream) == LoadedState.Completed) { try { Completed?.Invoke(this, mCompletedArgs.SetInfo(session, mRequest)); } finally { mRequest = null; } //if (pstream.Length == 0) // return; //goto START; return; } else { if (session.Server.EnableLog(LogType.Info)) { session.Server.Log(LogType.Info, session, $"{session.RemoteEndPoint} Multi receive to http request"); } if ((int)mRequest.State < (int)LoadedState.Header && pstream.Length > 1024 * 4) { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, "{0} http header too long!", session.RemoteEndPoint); } session.Dispose(); } else if (mRequest.Length > mServerConfig.MaxBodyLength) { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, "{0} http body too long!", session.RemoteEndPoint); } HttpToken token = (HttpToken)session.Tag; token.KeepAlive = false; var response = mRequest.CreateResponse(); InnerErrorResult innerErrorResult = new InnerErrorResult("413", "Request Entity Too Large"); response.Result(innerErrorResult); //session.Dispose(); return; } return; } }
private void OnHttpDecode(ISession session, PipeStream pstream) { START: if (mRequest == null) { mRequest = mServer.CreateRequest(session); } if (mRequest.Read(pstream) == LoadedState.Completed) { try { Completed?.Invoke(this, mCompletedArgs.SetInfo(session, mRequest)); } finally { mRequest = null; } if (pstream.Length == 0) { return; } goto START; } else { if (session.Server.EnableLog(LogType.Info)) { session.Server.Log(LogType.Info, session, $"{session.RemoteEndPoint} Multi receive to http request"); } if ((int)mRequest.State < (int)LoadedState.Header && pstream.Length > 1024 * 4) { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, "{0} http header too long!", session.RemoteEndPoint); } session.Dispose(); } else if (mRequest.Length > mServerConfig.MaxBodyLength) { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, "{0} http body too long!", session.RemoteEndPoint); } session.Dispose(); return; } return; } }
private void OnHttpDecode(ISession session, PipeStream pstream) { mReceives++; if (mRequest == null) { mRequest = mServer.CreateRequest(session); mRequest.ID = HttpRequest.GetID(); } if (mRequest.Read(pstream) == LoadedState.Completed) { try { Completed?.Invoke(this, mCompletedArgs.SetInfo(session, mRequest)); } finally { mRequest = null; mReceives = 0; } return; } else { HttpToken token = (HttpToken)session.Tag; if (session.Server.EnableLog(LogType.Info)) { session.Server.Log(LogType.Info, session, $"HTTP {mRequest.ID} {session.RemoteEndPoint} request from multi receive"); } if (mRequest.State == LoadedState.None) { if (mReceives > 2 || pstream.FirstBuffer.Length < 32) { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, $"HTTP {mRequest.ID} {session.RemoteEndPoint} receive data error!"); } token.KeepAlive = false; var response = mRequest.CreateResponse(); InnerErrorResult innerErrorResult = new InnerErrorResult("400", "Request http receive data error!"); response.Result(innerErrorResult); return; } var span = pstream.FirstBuffer.Memory.Slice(0, 10).Span; var method = Encoding.ASCII.GetString(span.ToArray()); bool ismethod = method.IndexOf("GET") == 0 || method.IndexOf("POST") == 0 || method.IndexOf("HEAD") == 0 || method.IndexOf("PUT") == 0 || method.IndexOf("DELETE") == 0 || method.IndexOf("CONNECT") == 0 || method.IndexOf("OPTIONS") == 0 || method.IndexOf("TRACE") == 0; if (!ismethod) { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, $"HTTP {mRequest.ID} {session.RemoteEndPoint} protocol data error!"); } token.KeepAlive = false; var response = mRequest.CreateResponse(); InnerErrorResult innerErrorResult = new InnerErrorResult("400", "Request http protocol data error!"); response.Result(innerErrorResult); return; } } if ((int)mRequest.State < (int)LoadedState.Header && (pstream.Length > 1024 * 4 || mReceives > 20)) { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, $"HTTP {mRequest.ID} {session.RemoteEndPoint} header too long!"); } token.KeepAlive = false; var response = mRequest.CreateResponse(); InnerErrorResult innerErrorResult = new InnerErrorResult("400", "Request header too large"); response.Result(innerErrorResult); } else if (mRequest.Length > mServerConfig.MaxBodyLength) { if (session.Server.EnableLog(LogType.Warring)) { session.Server.Log(LogType.Warring, session, $"HTTP {mRequest.ID} {session.RemoteEndPoint} body too long!"); } token.KeepAlive = false; var response = mRequest.CreateResponse(); InnerErrorResult innerErrorResult = new InnerErrorResult("400", "Request entity too large"); response.Result(innerErrorResult); return; } return; } }