Esempio n. 1
0
        protected override bool PostProcessRequestAsync(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, object responseObject)
        {
            var callback = httpReq.GetJsonpCallback();
            var doJsonp  = EndpointHost.Config.AllowJsonpRequests && !string.IsNullOrEmpty(callback);

            if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, responseObject, operationName))
            {
                return(true);
            }

            if (httpReq.ResponseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
            {
                JsvSyncReplyHandler.WriteDebugResponse(httpRes, httpReq, responseObject);
                return(true);
            }

            if (doJsonp)
            {
                httpRes.WriteToResponse(httpReq, responseObject, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
                {
                    return;
                }

                var restPath = GetRestPath(httpReq.HttpMethod, httpReq.ServicePath, httpReq.PathInfo);
                if (restPath == null)
                {
                    throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);
                }

                operationName = restPath.OperationName;

                var callback = httpReq.GetJsonpCallback();
                var doJsonp  = EndpointHost.Config.AllowJsonpRequests &&
                               !string.IsNullOrEmpty(callback);

                if (ResponseContentType != null)
                {
                    httpReq.ResponseContentType = ResponseContentType;
                }

                EndpointHost.Config.AssertContentType(httpReq.ResponseContentType);

                var request = GetRequest(httpReq, restPath);
                httpReq.RequestObject = request;
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request, operationName))
                {
                    return;
                }

                var response = GetResponse(httpReq, httpRes, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response, operationName))
                {
                    return;
                }

                if (httpReq.ResponseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
                {
                    JsvSyncReplyHandler.WriteDebugResponse(httpRes, httpReq, response);
                    return;
                }

                if (doJsonp)
                {
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                }
                else
                {
                    httpRes.WriteToResponse(httpReq, response);
                }
            }
            catch (Exception ex)
            {
                if (!EndpointHost.Config.WriteErrorsToResponse)
                {
                    throw;
                }
                HandleException(httpReq, httpRes, operationName, ex);
            }
            finally
            {
                if (EndpointHost.PostResponseFilters.Count > 0)
                {
                    EndpointHost.ApplyPostResponseFilters(new PostResponseFilterArgs()
                    {
                        ExecutionResult = httpRes.ExecutionResult,
                        ServicePath     = httpReq.ServicePath,
                        OperationName   = httpReq.OperationName,
                        RequestDeserializeTimeInMilliseconds = httpReq.DeserializationTimeInMillis,
                        ResponseSerializeTimeInMilliseconds  = httpRes.SerializationTimeInMillis
                    });
                }
            }
        }