Esempio n. 1
0
 public ControllerHandler(VirtualHostList virtualHostList, ChainControllerHandler chainControllerHandler, string serverName, string directoryRoot)
 {
     VirtualHostList        = virtualHostList;
     ChainControllerHandler = chainControllerHandler;
     ServerName             = serverName;
     DirectoryRoot          = directoryRoot;
 }
Esempio n. 2
0
        public ByteResponse Execute(string str, string clientIp)
        {
            HttpRequest  requestObject = null;
            HttpResponse httpResponse  = null;

            try
            {
                requestObject = new HttpRequest(str);
            }
            catch
            {
                httpResponse = new NotFound().HttpResponse;
            }

            var virtualHost = VirtualHostList.GetVirtualHost(requestObject != null ? requestObject.Host : "");
            var request     = new Request(requestObject, virtualHost);

            var accessLogHandler = new AccessLogHandler(Path.Combine(DirectoryRoot, "logs", virtualHost.AccessLog), clientIp, requestObject != null ? requestObject.UserAgent : "");

            if (httpResponse == null)
            {
                httpResponse = ChainControllerHandler.Execute(request).HttpResponse;
            }

            accessLogHandler.WriteInfo(request.Object.Method + " /" + request.Object.Uri.Url + " " + HttpResponseStatus.Get(httpResponse.HttpStatusCode));

            httpResponse.Headers.Add("Server", HttpServer.HttpServerName);
            httpResponse.Headers.Add("Date", new HttpDate(DateTime.Now).ToString());

            if (httpResponse.Content.IncludeBody && httpResponse.Content.Data == null)
            {
                httpResponse.Content.Data = GetErrorBody(httpResponse.HttpStatusCode);
            }

            return(new ByteResponse(httpResponse.GetBytes(), request.Object.KeepAlive));
        }