Click here to Skip to main content
15,892,927 members
Articles / Programming Languages / C#

MiniHttpd: an HTTP web server library

Rate me:
Please Sign up or sign in to vote.
4.86/5 (54 votes)
30 Dec 200514 min read 2M   9.8K   230  
A portable and flexible HTTP web server library written in 100% managed C#.
using System;
using System.IO;
using MiniHttpd;

namespace MiniHttpdApp
{
	public class HelloWorldFile : IFile
	{
		public HelloWorldFile(string name, IDirectory parent)
		{
			this.name = name;
			this.parent = parent;
		}

		string name;
		IDirectory parent;

		public void OnFileRequested(HttpRequest request, IDirectory directory)
		{
			// Assign a MemoryStream to hold the response content.
			request.Response.ResponseContent = new MemoryStream();

			// Create a StreamWriter to which we can write some text, and write to it.
			using(StreamWriter writer = new StreamWriter(request.Response.ResponseContent))
			{
				writer.WriteLine("Hello, world!");
			}
		}

		public string ContentType
		{
			get { return ContentTypes.GetExtensionType(".txt"); }
		}
		public string Name
		{
			get { return name; }
		}

		public IDirectory Parent
		{
			get { return parent; }
		}

		#region IDisposable Members

		public void Dispose()
		{
			// TODO:  Add HelloWorldFile.Dispose implementation
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Canada Canada
The cows are here to take me home now...

Comments and Discussions