Exemplo n.º 1
0
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                EndpointHost.Config.AssertFeatures(format);

                if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes))
                {
                    return;
                }

                httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
                var callback = httpReq.QueryString["callback"];
                var doJsonp  = EndpointHost.Config.AllowJsonpRequests &&
                               !string.IsNullOrEmpty(callback);

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

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

                if (doJsonp && !(response is CompressedResult))
                {
                    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);
            }
        }
Exemplo 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.PathInfo);
                if (restPath == null)
                {
                    throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);
                }

                operationName = restPath.RequestType.Name;

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

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

                var responseContentType = httpReq.ResponseContentType;
                EndpointHost.Config.AssertContentType(responseContentType);

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

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

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

                if (doJsonp && !(response is CompressedResult))
                {
                    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);
            }
        }