Ejemplo n.º 1
0
        public void Handle(HttpMessage.HttpSend message)
        {
            var deniedToHandle = message.Message as HttpMessage.DeniedToHandle;

            if (deniedToHandle != null)
            {
                int code;
                switch (deniedToHandle.Reason)
                {
                case DenialReason.ServerTooBusy:
                    code = HttpStatusCode.InternalServerError;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                message.HttpEntityManager.ReplyStatus(
                    code,
                    deniedToHandle.Details,
                    exc => Log.Debug("Error occurred while replying to HTTP with message {0}: {1}.", message.Message, exc.Message));
            }
            else
            {
                var response = message.Data;
                var config   = message.Configuration;
                message.HttpEntityManager.ReplyTextContent(
                    response,
                    config.Code,
                    config.Description,
                    config.ContentType,
                    config.Headers,
                    exc => Log.Debug("Error occurred while replying to HTTP with message {0}: {1}.", message.Message, exc.Message));
            }
        }
Ejemplo n.º 2
0
        public void Handle(HttpMessage.HttpSend message)
        {
            var deniedToHandle = message.Message as HttpMessage.DeniedToHandle;

            if (deniedToHandle != null)
            {
                int code;
                switch (deniedToHandle.Reason)
                {
                case DenialReason.ServerTooBusy:
                    code = HttpStatusCode.ServiceUnavailable;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                var start = _watch.ElapsedTicks;
                message.HttpEntityManager.ReplyStatus(
                    code,
                    deniedToHandle.Details,
                    exc => Log.Debug("Error occurred while replying to HTTP with message {message}: {e}.",
                                     message.Message, exc.Message));
                HistogramService.SetValue(_httpSendHistogram,
                                          (long)((((double)_watch.ElapsedTicks - start) / Stopwatch.Frequency) * 1000000000));
            }
            else
            {
                var response = message.Data;
                var config   = message.Configuration;
                var start    = _watch.ElapsedTicks;
                if (response is byte[])
                {
                    message.HttpEntityManager.ReplyContent(
                        response as byte[],
                        config.Code,
                        config.Description,
                        config.ContentType,
                        config.Headers,
                        exc => Log.Debug("Error occurred while replying to HTTP with message {message}: {e}.",
                                         message.Message, exc.Message));
                }
                else
                {
                    message.HttpEntityManager.ReplyTextContent(
                        response as string,
                        config.Code,
                        config.Description,
                        config.ContentType,
                        config.Headers,
                        exc => Log.Debug("Error occurred while replying to HTTP with message {message}: {e}.",
                                         message.Message, exc.Message));
                }

                HistogramService.SetValue(_httpSendHistogram,
                                          (long)((((double)_watch.ElapsedTicks - start) / Stopwatch.Frequency) * 1000000000));
            }
        }