internal HttpListenerContext(HttpConnection cnc, ILogger logger)
 {
     this.cnc = cnc;
     _logger = logger;
     request = new HttpListenerRequest(this);
     response = new HttpListenerResponse(this, _logger);
 }
Esempio n. 2
0
        /// <summary>
        /// Returns a string representation of the request body
        /// </summary>
        protected string GetPayload(HttpListenerRequest request)
        {
            try
            {
                string data;
                using (var reader = new StreamReader(request.InputStream, request.ContentEncoding))
                {
                    data = reader.ReadToEnd();
                }
                return data;
            }
            catch (Exception e)
            {
                EventLogger.Log(e);
            }

            return null;
        }
 /// <summary>
 /// Logs the request.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="request">The request.</param>
 private static void LogRequest(ILogger logger, HttpListenerRequest request)
 {
     logger.Info("{0} {1}. UserAgent: {2}", (request.IsWebSocketRequest ? "WS" : "HTTP " + request.HttpMethod), request.Url, request.UserAgent ?? string.Empty);
 }
        /// <summary>
        /// Logs the HTTP request.
        /// </summary>
        /// <param name="request">The request.</param>
        private void LogHttpRequest(HttpListenerRequest request)
        {
            var endpoint = request.LocalEndPoint;

            if (endpoint != null)
            {
                var address = endpoint.ToString();

                _endpointListener(address);
            }

            LogRequest(_logger, request);
        }
Esempio n. 5
0
        /// <summary>
        /// Logs the request.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="request">The request.</param>
        public static void LogRequest(ILogger logger, HttpListenerRequest request)
        {
            var url = request.Url.ToString();

            logger.Info("{0} {1}. UserAgent: {2}", request.IsWebSocketRequest ? "WS" : "HTTP " + request.HttpMethod, url, request.UserAgent ?? string.Empty);
        }
        /// <summary>
        /// Logs the request.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="request">The request.</param>
        private static void LogRequest(ILogger logger, HttpListenerRequest request)
        {
            var url = request.Url.ToString();
            var extension = Path.GetExtension(url);

            if (string.Equals(extension, ".js", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            if (string.Equals(extension, ".css", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            if (string.Equals(extension, ".woff", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            if (string.Equals(extension, ".woff2", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            if (string.Equals(extension, ".ttf", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            if (string.Equals(extension, ".html", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            logger.Info("{0} {1}. UserAgent: {2}", (request.IsWebSocketRequest ? "WS" : "HTTP " + request.HttpMethod), url, request.UserAgent ?? string.Empty);
        }
        /// <summary>
        /// Logs the request.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="request">The request.</param>
        private static void LogRequest(ILogger logger, HttpListenerRequest request)
        {
            var log = new StringBuilder();

            var headers = string.Join(",", request.Headers.AllKeys.Where(i => !string.Equals(i, "cookie", StringComparison.OrdinalIgnoreCase) && !string.Equals(i, "Referer", StringComparison.OrdinalIgnoreCase)).Select(k => k + "=" + request.Headers[k]));

            log.AppendLine("Ip: " + request.RemoteEndPoint + ". Headers: " + headers);

            var type = request.IsWebSocketRequest ? "Web Socket" : "HTTP " + request.HttpMethod;

            logger.LogMultiline(type + " " + request.Url, LogSeverity.Debug, log);
        }