/// <summary>
        /// 封装后的web请求默认处理器
        /// </summary>
        /// <param name="tch_request_info">解析过的web请求数据</param>
        /// <returns></returns>
        public TchResponseInfo ProcessTchRequest(TchRequestInfo tch_request_info)
        {
            TchResponseInfo tch_response_info = this.GetResponseInfoFormFilter(tch_request_info.Uri.AbsolutePath);

            if (tch_response_info != null)
            {
                return(tch_response_info);
            }

            tch_response_info = this.GetResponseInfoFormFile(tch_request_info);
            if (tch_response_info != null)
            {
                return(tch_response_info);
            }

            tch_response_info = this.GetResponseInfoFormResource(tch_request_info);
            if (tch_response_info != null)
            {
                return(tch_response_info);
            }

            //未找到任何资源
            Application.This.OnError(-1, $"[{tch_request_info.Uri.AbsolutePath}] File Not Found");
            return(TchHelper.ParseToResponse(Encoding.UTF8.GetBytes($"<html><head><meta charset=\"UTF-8\"/><title>处理请求错误</title></head><body><h1>{tch_request_info.Uri.AbsolutePath}没找到</h1></body></html>"), 404, "File Not Found"));
        }
Beispiel #2
0
        public static TchResponseInfo ParseToResponse(byte[] body_bytes, int status_code = 200, string status_text = "OK", string mime_type = "text/html")
        {
            TchResponseInfo info = new TchResponseInfo();

            info.StatusCode = status_code;
            info.StatusText = status_text;
            info.MimeType   = mime_type;
            StringBuilder header_builder = new StringBuilder();

            //info.Headers.Add("Connection", "keep-alive");
            info.Headers.Add("Encoding", "UTF-8");
            info.Headers.Add("Content-Length", body_bytes.Length.ToString());
            info.Headers.Add("Content-Type", mime_type + "; charset=UTF-8");
            info.Body = body_bytes;
            return(info);
        }