/// <summary> /// 输出结束 /// </summary> /// <param name="response">HTTP响应输出</param> /// <returns>是否操作成功</returns> internal unsafe bool SocketResponse(ref AutoCSer.Net.Http.Response response) { long identity = SocketIdentity; AutoCSer.Net.Http.SocketBase socket = Socket; try { AutoCSer.Net.Http.Header header = socket.HttpHeader; AutoCSer.Net.Http.HeaderFlag flag = header.Flag; if ((flag & AutoCSer.Net.Http.HeaderFlag.IsVersion) != 0 && (flag & Net.Http.HeaderFlag.IsRange) == 0) { response.TryStaticFileCacheControl(); } switch (response.Type) { case Net.Http.ResponseType.ByteArray: case Net.Http.ResponseType.SubByteArray: case Net.Http.ResponseType.SubBuffer: if ((flag & Net.Http.HeaderFlag.IsRange) == 0) { #if DOTNET2 || DOTNET4 if ((flag & Net.Http.HeaderFlag.IsGZip) != 0 && isGZip) { response.Compress(); } #else if ((flag & Net.Http.HeaderFlag.IsGZip) != 0 && isGZip) { response.Compress(DomainServer.WebConfigIsFastestCompressionLevel); } #endif response.NoStore200(DomainServer.HtmlContentType); } else if (header.FormatRange(response.Body.Array.Length)) { response.NoStore200(DomainServer.HtmlContentType); } else if (socket.ResponseError(identity, AutoCSer.Net.Http.ResponseState.RangeNotSatisfiable416)) { return(true); } break; //case Net.Http.ResponseType.File: response.SetState(AutoCSer.Net.Http.ResponseState.Ok200); break; } if (socket.Response(identity, ref response)) { return(true); } } finally { AutoCSer.Net.Http.Response.Push(ref response); } return(false); }
/// <summary> /// 加载 AJAX 调用 /// </summary> /// <param name="ajax"></param> /// <param name="ajaxInfo"></param> protected void loadAjax(AutoCSer.WebView.Ajax ajax, AutoCSer.WebView.AjaxMethodInfo ajaxInfo) { AutoCSer.Net.Http.Header header = Socket.HttpHeader; ajax.LoadHeader(DomainServer, Socket, ajaxInfo.IsAsynchronous); if (header.Method == AutoCSer.Net.Http.MethodType.POST && header.ContentLength != 0) { ajax.SetLoader(this, ajaxInfo); Socket.GetForm(ajax, AutoCSer.Net.Http.GetFormType.Ajax); } else if (!this.callAjax(ajaxInfo.MethodIndex, ajax)) { Socket.ResponseError(SocketIdentity, AutoCSer.Net.Http.ResponseState.ServerError500); } }
/// <summary> /// AJAX调用 /// </summary> protected void load() { try { AutoCSer.Net.Http.SocketBase socket = Socket; AutoCSer.Net.Http.Header header = Socket.HttpHeader; if ((header.Flag & Net.Http.HeaderFlag.IsSetAjaxCallName) != 0) { #if MONO AutoCSer.WebView.AjaxMethodInfo call = methods.Get(header.AjaxCallNameData); #else AutoCSer.WebView.AjaxMethodInfo call = DomainServer.WebConfigIgnoreCase ? methods.GetLower(header.AjaxCallNameData) : methods.Get(header.AjaxCallNameData); #endif if (call == null) { byte[] path = DomainServer.GetViewRewrite(header.AjaxCallNameData); if (path.length() != 0) { call = methods.GetNotEmpty(path); } } if (call != null && (!call.IsReferer || header.IsReferer != 0))// || AutoCSer.Config.Pub.Default.IsDebug { if (call.IsViewPage) { if (header.Method == Net.Http.MethodType.GET) { loadView(call); return; } } else if ((header.Method == Net.Http.MethodType.POST || !call.IsPost)) { if (header.ContentLength <= call.MaxPostDataSize) { loadAjax(call); } else { socket.ResponseErrorIdentity(AutoCSer.Net.Http.ResponseState.ServerError500); } return; } } } socket.ResponseErrorIdentity(AutoCSer.Net.Http.ResponseState.NotFound404); } finally { PushPool(); } }
/// <summary> /// 公用错误处理函数 /// </summary> protected void pubError() { AutoCSer.Net.Http.Header header = Socket.HttpHeader; if (header.Method == AutoCSer.Net.Http.MethodType.POST && header.ContentLength != 0) { PubAjax ajax = PubAjax.Pop() ?? new PubAjax(); ajax.LoadHeader(DomainServer, Socket, true, ajax); Socket.GetForm(ajax, AutoCSer.Net.Http.GetFormType.PubAjax); return; } else { Socket.ResponseErrorIdentity(Net.Http.ResponseState.ServerError500); } }
/// <summary> /// 加载 AJAX 调用 /// </summary> /// <param name="ajax"></param> /// <param name="ajaxInfo"></param> protected void loadAjax <ajaxType>(ajaxType ajax, AutoCSer.WebView.AjaxMethodInfo ajaxInfo) where ajaxType : AutoCSer.WebView.Ajax <ajaxType> { AutoCSer.Net.Http.Header header = Socket.HttpHeader; ajax.LoadHeader(DomainServer, Socket, ajaxInfo.IsAsynchronous, ajax); if (header.Method == AutoCSer.Net.Http.MethodType.POST && header.ContentLength != 0) { ajax.SetLoader(this, ajaxInfo); Socket.GetForm(ajax, AutoCSer.Net.Http.GetFormType.Ajax); return; } if (this.callAjax(ajaxInfo.MethodIndex, ajax)) { return; } Socket.ResponseError(SocketIdentity, AutoCSer.Net.Http.ResponseState.ServerError500); ajax.PushPool(); }
/// <summary> /// 解析web调用参数 /// </summary> /// <typeparam name="parameterType">web调用参数类型</typeparam> /// <param name="parameter">web调用参数</param> /// <returns>是否成功</returns> protected bool parseParameterQueryAny <parameterType>(ref parameterType parameter) { AutoCSer.Net.Http.Header header = Socket.HttpHeader; if (header.ParseQuery(ref parameter)) { string queryJson = header.QueryJson; if (queryJson != null) { return(AutoCSer.Json.Parser.ParseNotEmpty(queryJson, ref parameter, jsonParserConfig)); } string queryXml = header.QueryXml; if (queryXml != null) { return(AutoCSer.Xml.Parser.Parse(queryXml, ref parameter, xmlParserConfig)); } return(true); } return(false); }
/// <summary> /// 解析web调用参数 /// </summary> /// <typeparam name="parameterType">web调用参数类型</typeparam> /// <param name="parameter">web调用参数</param> /// <returns>是否成功</returns> protected bool parseParameterQuery <parameterType>(ref parameterType parameter) where parameterType : struct { AutoCSer.Net.Http.Header header = Socket.HttpHeader; if (header.ParseQuery(ref parameter)) { string queryJson = header.QueryJson; if (queryJson != null) { return(parseJson(ref parameter, queryJson)); } string queryXml = header.QueryXml; if (queryXml != null) { return(AutoCSer.Xml.Parser.Parse(queryXml, ref parameter, xmlParserConfig)); } return(true); } return(false); }