Exemple #1
0
        /// <summary>
        /// 加载 HTTP 调用[TRY]
        /// </summary>
        /// <typeparam name="callType"></typeparam>
        /// <param name="socket">HTTP套接字接口</param>
        /// <param name="call">HTTP 调用</param>
        /// <param name="callInfo">HTTP 调用函数信息</param>
        protected void loadAsynchronous <callType>(Http.SocketBase socket, callType call, AutoCSer.WebView.CallMethodInfo callInfo)
            where callType : AutoCSer.WebView.CallAsynchronous <callType>
        {
            Http.Header header = socket.HttpHeader;
            if (header.ContentLength <= callInfo.MaxPostDataSize && (header.Method == Http.MethodType.POST || !callInfo.IsOnlyPost))
            {
                call.LoadHeader(this, socket, call, callInfo);
                if (header.Method == Http.MethodType.POST && header.ContentLength != 0)
                {
                    socket.GetForm(call, Http.GetFormType.CallAsynchronous);
                    return;
                }
                long socketIdentity = socket.Identity;
                if (this.call(call))
                {
                    return;
                }
                call.PushPool();
                socket.ResponseError(socketIdentity, Http.ResponseState.ServerError500);
            }
            else
            {
                AutoCSer.WebView.CallAsynchronous <callType> .PushNotNull(call);

                socket.ResponseErrorIdentity(Http.ResponseState.ServerError500);
            }
        }
Exemple #2
0
 /// <summary>
 /// HTTP请求处理[TRY]
 /// </summary>
 /// <param name="socket">HTTP套接字</param>
 public override unsafe void Request(Http.SocketBase socket)
 {
     Http.Response response = file(socket.HttpHeader);
     if (response != null)
     {
         socket.ResponseIdentity(ref response);
     }
     else
     {
         socket.ResponseErrorIdentity(Http.ResponseState.NotFound404);
     }
 }
Exemple #3
0
 /// <summary>
 /// 加载页面视图
 /// </summary>
 /// <param name="socket">HTTP套接字接口</param>
 /// <param name="view">WEB视图接口</param>
 internal void LoadAjax(Http.SocketBase socket, AutoCSer.WebView.View view)
 {
     if (socket.HttpHeader.Method == Http.MethodType.GET)
     {
         if (view.LoadHeader(this, socket))
         {
             view.LoadAjax();
         }
     }
     else
     {
         socket.ResponseErrorIdentity(Http.ResponseState.ServerError500);
     }
 }
Exemple #4
0
 /// <summary>
 /// 加载页面视图[TRY]
 /// </summary>
 /// <param name="socket">HTTP套接字接口</param>
 /// <param name="view">WEB视图接口</param>
 /// <param name="isAsynchronous">是否异步</param>
 /// <param name="isAwaitMethod">是否存在 await 函数</param>
 protected void loadPage(Http.SocketBase socket, AutoCSer.WebView.View view, bool isAsynchronous, bool isAwaitMethod)
 {
     if (socket.HttpHeader.Method == Http.MethodType.GET)
     {
         view.SetAsynchronousAwaitMethod(isAsynchronous, isAwaitMethod);
         if (view.LoadHeader(this, socket))
         {
             view.LoadPage();
         }
     }
     else
     {
         socket.ResponseErrorIdentity(Http.ResponseState.ServerError500);
     }
 }
Exemple #5
0
        /// <summary>
        /// 加载页面视图
        /// </summary>
        /// <param name="socket">HTTP套接字接口</param>
        /// <param name="view">WEB视图接口</param>
        internal void LoadAjax <viewType>(Http.SocketBase socket, viewType view)
            where viewType : AutoCSer.WebView.View <viewType>
        {
            if (socket.HttpHeader.Method == Http.MethodType.GET)
            {
                if (view.LoadHeader(this, socket, view))
                {
                    view.LoadAjax();
                }
            }
            else
            {
                AutoCSer.WebView.View <viewType> .PushNotNull(view);

                socket.ResponseErrorIdentity(Http.ResponseState.ServerError500);
            }
        }
 /// <summary>
 /// HTTP请求处理[TRY]
 /// </summary>
 /// <param name="socket">HTTP套接字</param>
 public override unsafe void Request(Http.SocketBase socket)
 {
     if ((socket.HttpHeader.Flag & Http.HeaderFlag.IsSetIfModifiedSince) == 0)
     {
         Http.Response response = file(socket.HttpHeader);
         if (response != null)
         {
             socket.ResponseIdentity(ref response);
         }
         else
         {
             socket.ResponseErrorIdentity(Http.ResponseState.NotFound404);
         }
     }
     else
     {
         socket.ResponseIdentity(Http.Response.NotChanged304);
     }
 }
Exemple #7
0
 /// <summary>
 /// 加载web调用
 /// </summary>
 /// <param name="socket">HTTP套接字接口</param>
 /// <param name="call">web调用</param>
 /// <param name="callInfo">HTTP 调用函数信息</param>
 protected void load(Http.SocketBase socket, AutoCSer.WebView.Call call, AutoCSer.WebView.CallMethodInfo callInfo)
 {
     Http.Header header = socket.HttpHeader;
     if (header.ContentLength <= callInfo.MaxPostDataSize && (header.Method == Http.MethodType.POST || !callInfo.IsOnlyPost))
     {
         call.LoadHeader(this, socket, callInfo);
         if (header.Method == Http.MethodType.POST && header.ContentLength != 0)
         {
             socket.GetForm(call, Http.GetFormType.Call);
             return;
         }
         long socketIdentity = socket.Identity;
         if (this.callSynchronize(call))
         {
             return;
         }
         socket.ResponseError(socketIdentity, Http.ResponseState.ServerError500);
     }
     else
     {
         socket.ResponseErrorIdentity(Http.ResponseState.ServerError500);
     }
 }
Exemple #8
0
        /// <summary>
        /// WebSocket请求处理
        /// </summary>
        /// <param name="socket">HTTP套接字</param>
        public override void WebSocketRequest(Http.SocketBase socket)
        {
            int index = webSocketSearcher.Search(socket.HttpHeader.Path);

            if (index >= 0)
            {
                long socketIdentity = socket.Identity;
                try
                {
                    callWebSocket(index, socket);
                    return;
                }
                catch (Exception error)
                {
                    socket.ResponseError(socketIdentity, Http.ResponseState.ServerError500);
                    RegisterServer.TcpServer.Log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
                }
            }
            else
            {
                socket.ResponseErrorIdentity(Http.ResponseState.NotFound404);
            }
        }
Exemple #9
0
 /// <summary>
 /// webSocket调用处理
 /// </summary>
 /// <param name="callIndex"></param>
 /// <param name="socket"></param>
 protected virtual void callWebSocket(int callIndex, Http.SocketBase socket)
 {
     socket.ResponseErrorIdentity(Http.ResponseState.ServerError500);
 }
Exemple #10
0
        /// <summary>
        /// HTTP请求处理[TRY]
        /// </summary>
        /// <param name="socket">HTTP套接字</param>
        public override unsafe void Request(Http.SocketBase socket)
        {
            Http.Header     header = socket.HttpHeader;
            SubArray <byte> path   = header.Path;
            int             index;

            if (header.IsSearchEngine == 0)
            {
                byte[] rewritePath;
#if !MONO
                if (WebConfigIgnoreCase)
                {
                    if ((index = callSearcher.SearchLower(ref path)) >= 0)
                    {
                        call(index, socket);
                        return;
                    }
                    rewritePath = rewritePaths.GetLower(ref path);
                }
                else
#endif
                {
                    if ((index = callSearcher.Search(ref path)) >= 0)
                    {
                        call(index, socket);
                        return;
                    }
                    rewritePath = rewritePaths.Get(ref path);
                }
                if (rewritePath != null)
                {
                    Http.Response response = null;
                    file(header, file(rewritePath, (header.Flag & Http.HeaderFlag.IsSetIfModifiedSince) == 0 ? new SubArray <byte>() : header.IfModifiedSince, ref response, false), ref response);
                    if (response != null)
                    {
                        socket.ResponseIdentity(ref response);
                        return;
                    }
                    socket.ResponseErrorIdentity(Http.ResponseState.NotFound404);
                }
            }
            else
            {
#if !MONO
                if (WebConfigIgnoreCase)
                {
                    if ((index = rewriteSearcher.SearchLower(ref path)) >= 0)
                    {
                        request(index, socket);
                        return;
                    }
                    if ((index = viewSearcher.SearchLower(ref path)) >= 0)
                    {
                        request(index, socket);
                        return;
                    }
                    if ((index = callSearcher.SearchLower(ref path)) >= 0)
                    {
                        call(index, socket);
                        return;
                    }
                }
                else
#endif
                {
                    if ((index = rewriteSearcher.Search(ref path)) >= 0)
                    {
                        request(index, socket);
                        return;
                    }
                    if ((index = viewSearcher.Search(ref path)) >= 0)
                    {
                        request(index, socket);
                        return;
                    }
                    if ((index = callSearcher.Search(ref path)) >= 0)
                    {
                        call(index, socket);
                        return;
                    }
                }
            }
            if (beforeFile(socket))
            {
                base.Request(socket);
            }
        }
Exemple #11
0
        /// <summary>
        /// HTTP请求处理[TRY]
        /// </summary>
        /// <param name="socket">HTTP套接字</param>
        public override unsafe void Request(Http.SocketBase socket)
        {
            Http.Header header = socket.HttpHeader;
            if (((uint)header.ContentLength | (uint)header.IsBoundary) == 0)
            {
                Http.Response            response = Http.Response.Get();
                SubBuffer.PoolBufferFull buffer   = header.Buffer;
                byte[]      domain = socket.IsSsl ? sslLocationDomain : locationDomain, bufferArray = buffer.Buffer;
                BufferIndex uri    = header.UriIndex;
                int         length = domain.Length + uri.Length;
                if (uri.Length != 0)
                {
                    if (bufferArray[buffer.StartIndex + uri.StartIndex] == '/')
                    {
                        uri.Next();
                        if (uri.Length == 0)
                        {
                            goto END;
                        }
                        --length;
                    }
                    if (length <= header.HeaderEndIndex)
                    {
                        int startIndex = uri.StartIndex - domain.Length;
                        if (startIndex >= 0)
                        {
                            Buffer.BlockCopy(domain, 0, bufferArray, startIndex += buffer.StartIndex, domain.Length);
                            response.SetLocation(bufferArray, startIndex, length, locationState);
                        }
                        else
                        {
                            Buffer.BlockCopy(bufferArray, buffer.StartIndex + uri.StartIndex, bufferArray, buffer.StartIndex + domain.Length, uri.Length);
                            Buffer.BlockCopy(domain, 0, bufferArray, buffer.StartIndex, domain.Length);
                            response.SetLocation(bufferArray, buffer.StartIndex, length, locationState);
                        }
                        socket.ResponseIdentity(ref response);
                        return;
                        //int endIndex = uri.EndIndex;
                        //if (header.HeaderEndIndex - endIndex - 7 >= length)
                        //{
                        //    fixed (byte* bufferFixed = bufferArray)
                        //    {
                        //        byte* bufferStart = bufferFixed + buffer.StartIndex, write = bufferStart + endIndex;
                        //        Memory.SimpleCopyNotNull64(domain, write, domain.Length);
                        //        Memory.SimpleCopyNotNull64(bufferStart + uri.StartIndex, write + domain.Length, uri.Length);
                        //    }
                        //    response.SetLocation(bufferArray, buffer.StartIndex + endIndex, length, locationState);
                        //    socket.Response(socketIdentity, ref response);
                        //    return;
                        //}
                    }
                }
END:
                response.SetLocation(domain, locationState);
                socket.ResponseIdentity(ref response);
            }
            else
            {
                socket.ResponseErrorIdentity(Http.ResponseState.BadRequest400);
            }
        }
Exemple #12
0
 /// <summary>
 /// WebSocket请求处理
 /// </summary>
 /// <param name="socket">HTTP套接字</param>
 public virtual void WebSocketRequest(Http.SocketBase socket)
 {
     socket.ResponseErrorIdentity(Http.ResponseState.NotFound404);
 }