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

Small and Reliable C++ HTTP Server with Complete ASP.NET Support

Rate me:
Please Sign up or sign in to vote.
4.78/5 (24 votes)
5 Feb 2009CPOL8 min read 74.3K   1.6K   81  
This article describes results of ahttpserver evolution - implementation of ASP.NET handler and many architecture improvements
<?xml version="1.0" encoding="utf-8"?>
<settings>

	<!-- timeouts defined in seconds -->
	<!-- 
		Default values in code:
		workers-count="500"
		pooling-enabled="true"
		worker-life-time="300"

		keep-alive-timeout = "5"
		server-socket-timeout = "900"
		command-socket-timeout = "30" 
		response-buffer-size = "2048576" bytes
		
		{app-path} can be used in 'uploads-dir'
		-->

	<server
		version = "ahttp/0.19"
		port="5555"
		ip-address="0.0.0.0"
		workers-count="50"
		pooling-enabled="true"
		worker-life-time="60"
		command-port="5556"
		root="root"

		keep-alive-enabled = "true"
		keep-alive-timeout = "10"
		server-socket-timeout = "900"
		command-socket-timeout = "30"
				
		response-buffer-size = "8194304"
		max-chunk-size = "512144"

		directory-config-file = "directory.config"
		messages-file = "messages.config"
		
		uploads-dir = "c:\\temp\\ahttp"
		locale=".1251"
		>


		<!-- log-level: "Debug", "Info", "Warning", "Error", "Critical" - if none of them - then debug -->
		<log log-level="info" max-file-size="4194304">

			<!-- {app-path} - path to directory where application is located (with trailing slash),
				 {timestamp} - generated timestamp -->
			<path>{app-path}log\server_{timestamp}.log</path>
		</log>

		<mime-types file="{app-path}mime-types.config" />

		<!-- All handlers must be registered there, concrete 
			assignments will be defined in <directory> elements -->
		<handlers>
			<register name="handler_python" default-ext=".py; .pyhtml">
				<path>{app-path}handler_python-d.dll</path>
				<!-- parameter name="uploads-dir">c:\temp\handler_python\</parameter -->
			</register>
			<register name="handler_php" default-ext=".php">
				<path>{app-path}handler_isapi-d.dll</path>
				<parameter name="engine">c:\PHP\php5isapi.dll</parameter>
				<parameter name="update-path">c:\PHP\</parameter>
				<parameter name="free-library">false</parameter>
				<parameter name="check-file-exists">true</parameter>
			</register>
			<register name="handler_aspnet" default-ext=".aspx; .ashx; .asmx; .axd">
				<path>{app-path}handler_aspnet-d.dll</path>
				<parameter name="init-root">false</parameter>
				<!-- parameter name="load-applications">mvc; books</parameter -->
			</register>
		</handlers>

	</server>

	<!-- virtual-path for root: "/"
				'charset' - will be used when FS content is shown   
				default 'max-request-size': 2097152 bytes -->
	<directory name="root"
			browsing-enabled="true"
			charset="Windows-1251"
			max-request-size="2097152"
			enable-parent-path-access="true">

		<path>d:\work\web\</path>

		<default-documents>
			<add>index.html</add>
			<add>index.htm</add>
			<add>main.html</add>
            <add>Default.aspx</add>
		</default-documents>

		<!-- ext="*" - will be applied to all requests -->
		<!-- ext="." - will be applied to directory/file without extension -->
		<handlers>
			<add name="handler_python"/>
			<add name="handler_php" />
			<add name="handler_aspnet"/>
       </handlers>

		<!-- Record attributes: 
				{name} - name of item, 
				{size} - size of item in kb,
				{url} - url to open item
				{time} - last modify dat/time of item,
				{page-url} - url to current page
				{parent-url} - url to parent directory
				{files-count} - files count in current directory
				{directories-count} - sub-directories count in current directory
				{errors-count} - reading errors count 
				{tab} - will be replaced with '\t'
		-->
		<header-template>
			&lt;html&gt;
			&lt;head&gt;
			&lt;title&gt;Directory content: {page-url}&lt;/title&gt;
			&lt;style&gt;
			BODY { padding: 10px; margin: 10px; font: 10pt Tahoma, Arial; color: #000;}
			H1 {font-size: 12pt; font-weight: bold; }
			HR {height:1px; border: 1px solid #333; color: #333;}
			TABLE {font-size: 100%;}
			TD {padding: 1px 10px 0px 10px; text-align: left; }

			&lt;/style&gt;
			&lt;/head&gt;
			&lt;body&gt;
			&lt;h1&gt;Directory: &lt;i&gt;{page-url}&lt;/i&gt;&lt;/h1&gt;
			&lt;hr /&gt;
			&lt;table border="0" cellpadding="0" cellspacing="0"&gt;
		</header-template>

		<parent-directory-template >
			&lt;tr&gt;&lt;td colspan="4" style="padding-bottom: 10px;"&gt;&lt;a href="{parent-url}"&gt;[parent directory]&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
		</parent-directory-template>

		<directory-template>
			&lt;tr&gt;
			&lt;td&gt;{time}&lt;/td&gt;
			&lt;td&gt; &amp;lt;dir&amp;gt; &lt;/td&gt;
			&lt;td&gt; &lt;img border="0" align="middle" src="/server_data/images/icon_dir.gif"/&gt; &lt;/td&gt;
			&lt;td&gt; &lt;a href="{url}"&gt;  {name}&lt;/a&gt; &lt;/td&gt;
			&lt;/tr&gt;
		</directory-template>

		<virtual-directory-template >
			&lt;tr&gt;
			&lt;td&gt;{time}&lt;/td&gt;
			&lt;td&gt; &amp;lt;virtual&amp;gt; &lt;/td&gt;
			&lt;td&gt; &lt;img border="0" align="middle" src="/server_data/images/icon_virtual_dir.gif"/&gt; &lt;/td&gt;
			&lt;td&gt;&lt;a href="{url}"&gt;{name}&lt;/a&gt;&lt;/td&gt;
			&lt;/tr&gt;
		</virtual-directory-template>

		<file-template >
			&lt;tr&gt;
			&lt;td&gt;{time}&lt;/td&gt;
			&lt;td&gt;{size}&lt;/td&gt;
			&lt;td&gt; &lt;img border="0" align="middle" src="/server_data/images/icon_file.gif"/&gt; &lt;/td&gt;
			&lt;td&gt;&lt;a href="{url}"&gt;{name}&lt;/a&gt;&lt;/td&gt;
			&lt;/tr&gt;
		</file-template>

		<footer-template>
			&lt;/table&gt;
			&lt;hr /&gt;
			Files: {files-count}&lt;br&gt;
			Directories: {directories-count}&lt;br&gt;
			Reading errors: {errors-count}
			&lt;hr /&gt;
			&lt;/body&gt;
			&lt;/html&gt;
		</footer-template>

	</directory>

	<directory name="server_data"
			parent="root">
		<virtual-path>server_data</virtual-path>
		<path>{app-path}web</path>
	</directory>
    
    <directory name="books"
			parent="root">
		<virtual-path>books</virtual-path>
		<path>d:\work\Visual Studio 2008\WebSites\WordWheel\</path>
	</directory>

	<directory name="mvc"
		   parent="root">
		<handlers>
			<add name="handler_aspnet" ext="*"/>
			<remove name="handler_aspnet" ext=".gif; .js; .css; .jpg; .png"/>
		</handlers>
		<virtual-path>mvc</virtual-path>
		<path>d:\work\Visual Studio 2008\Projects\OReilly-.NET3.5\MVCApplication\</path>
	</directory>
        

	<directory name="disk_c"
		parent="root">
		<handlers>
			<clear />
		</handlers>
		<virtual-path>disk_c</virtual-path>
		<path>c:\</path>
	</directory>


</settings>

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Belarus Belarus
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions