Exemplo n.º 1
0
 public void HandleRequest(string uri, HttpRequest request, HttpResponse response, HttpContext context)
 {
     if (request.Method != HttpMethod.Get)
         throw new HttpMethodNotAllowedException();
     // Replace '/' with '.' to generate the resource name
     string resourceName = uri.Replace('/', '.');
     if (resourceName.StartsWith("."))
         resourceName = m_prefix + resourceName;
     else
         resourceName = string.Format("{0}.{1}", m_prefix, resourceName);
     Stream resource = null;
     // If we are not expecting a directory, try and load the stream
     if (!resourceName.EndsWith("."))
         resource = m_assembly.GetManifestResourceStream(resourceName);
     else
         resourceName = resourceName.Substring(0, resourceName.Length - 1);
     // If nothing found try and load the default filename instead
     if ((resource == null) && (m_defaultFile != null))
     {
         // Try the default file
         resourceName = string.Format("{0}.{1}", resourceName, m_defaultFile);
         resource = m_assembly.GetManifestResourceStream(resourceName);
     }
     if (resource == null)
         throw new HttpNotFoundException();
     // Get the mime type and send the file
     response.Headers[HttpHeaders.ContentType] = MimeType.FromExtension(resourceName);
     resource.CopyTo(response.Content);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Handle the request
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <param name="context"></param>
        public void HandleRequest(string uri, HttpRequest request, HttpResponse response, HttpContext context)
        {
            // Split into path and filename
            int index = uri.LastIndexOf('/');
            string path = (index < 0) ? "" : uri.Substring(0, index);
            string filename = (index < 0) ? uri : uri.Substring(index + 1);
            // Use default filename if applicable
            if (filename.Length == 0)
                filename = m_defaultFile;
            // Strip leading separators from URI
            if (path.StartsWith("/"))
                path = path.Substring(1);
            // Now look for the file
            IFolder folder = m_basePath.OpenChild(path);
            if (folder == null)
                throw new HttpNotFoundException();
            if (!folder.FileExists(filename))
                throw new HttpNotFoundException();
            // Get the content type
            response.ResponseCode = HttpResponseCode.Ok;
            response.ContentType = MimeType.FromExtension(filename);

            using(Stream input = folder.CreateFile(filename, FileAccessMode.Read, CreationOptions.OpenIfExists))
                input.CopyTo(response.Content);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Apply all the filters to the current request
 /// </summary>
 /// <param name="request"></param>
 /// <param name="response"></param>
 /// <param name="context"></param>
 internal void ApplyFilters(HttpRequest request, HttpResponse response, HttpContext context)
 {
     lock (m_filters)
     {
         foreach (IHttpFilter filter in m_filters)
             filter.ApplyFilter(request, response, context);
     }
 }
Exemplo n.º 4
0
		/// <summary>
		/// Apply all the filters to the current request
		/// </summary>
		/// <param name="request"></param>
		/// <param name="response"></param>
		/// <param name="context"></param>
		internal void ApplyAfterFilters(HttpRequest request, HttpResponse response, HttpContext context)
		{
			lock (m_filters)
			{
				foreach (IHttpFilter filter in m_filters)
				{
					try
					{
						filter.After(request, response, context);
					}
					catch (Exception)
					{
						// Just silently ignore it
					}
				}
			}
		}
Exemplo n.º 5
0
        /// <summary>
        /// Apply all the filters to the current request
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <param name="context"></param>
        internal bool ApplyBeforeFilters(HttpRequest request, HttpResponse response, HttpContext context)
        {
			bool allowHandling = true;
            lock (m_filters)
            {
				foreach (IHttpFilter filter in m_filters)
				{
					try
					{
						allowHandling = allowHandling && filter.Before(request, response, context);
					}
					catch (Exception)
					{
						// Just silently ignore it
					}
				}
            }
			return allowHandling;
        }