Ejemplo n.º 1
0
        public HTTPResponse GetResource(HTTPHeaderData headers)
        {
            string resourceLoc = GetFinalResourceLocation(headers);
            HTTPResponse response = new HTTPResponse(headers.HTTPVersion, EHTTPResponse.R200_OK);

            if (File.Exists(resourceLoc))
            {
                response.SetResponseBody(File.ReadAllBytes(resourceLoc), MIMETypeManager.GetMIMEFromFilePath(resourceLoc), File.GetLastWriteTimeUtc(resourceLoc));
                response.SetETag(resourceLoc);
            }
            else
            {
                return SimpleResponseManager.PrepareSimpleResponse(EHTTPResponse.R404_NotFound, headers, this);
            }

            return response;
        }
Ejemplo n.º 2
0
        public static HTTPResponse PrepareSimpleResponse(EHTTPResponse responseCode, HTTPHeaderData requestHeaders, VirtualHost host = null)
        {
            HTTPResponse response = new HTTPResponse(requestHeaders == null ? EHTTPVersion.HTTP10 : requestHeaders.HTTPVersion, responseCode);

            string responseBody = null;
            if (host != null)
            {

            }

            if (responseBody == null)
                responseBody = SimpleResponsePageLayout;

            string generatedInfo = "Generated by " + Program.GetFullProgramVersionString() + " on " + DateTime.Now.ToUniversalTime().ToString("r");

            responseBody = responseBody
                .Replace("{BISMUTH_RESPONSE_NAME}", HTTPHeaderData.GetResponseCodeString(responseCode))
                .Replace("{BISMUTH_RESPONSE_DESC}", HTTPHeaderData.GetResponseCodeInfo(responseCode, requestHeaders, host))
                .Replace("{BISMUTH_RESPONSE_GENERATED_INFO}", generatedInfo);

            response.SetResponseBody(responseBody, "text/html");
            return response;
        }