<html>
<head><title>HTTP: Embedded HTTP server</title></head>
<body>
<h2>HTTP.dll: Embedded HTTP server</h2>
<p>The HTTP assembly contains the classes to run a simple HTTP server. Requires Sockets.dll.</p>
<p class="byline">Namespace: RedCorona.Net</p>
<ul>
<li><a href="#HttpServer">HttpServer</a> class
<li><a href="#HttpRequest">HttpRequest</a> class
<li><a href="#HttpResponse">HttpResponse</a> class
<li><a href="#IHttpHandler">IHttpHandler</a> interface
<li><a href="#Session">Session</a> class
<li><a href="#SubstitutingFileHandler">SubstitutingFileHandler</a> class
</ul>
<hr>
<h3><a name="ByteBuilder">HttpServer class</a></h3>
<p>This class encapsulates a HTTP server, and manages sessions, header and query string parsing and processing of requests and responses.</p>
<p><B>Properties:</b></p>
<dl>
<dt><b>public Hashtable Hostmap</b> (read only); Generic equivalent type: Hashtable<string,string></dt>
<dd>A mapping between hostnames and home folders.</dd>
<dt><b>public ArrayList Handlers</b> (read only); Generic equivalent type: List<IHttpHandler></dt>
<dd>The list of request handlers currently attached to this server. You should only add instances of IHttpHandler to this list, and you should not clear the list. It should always contain at least one handler which is guaranteed to process every request, which it does on initialisation.</dd>
<dt><b>public Server Server</b> (read only)</dt>
<dd>The underlying <a href="Sockets.htm#Server">Sockets server</a>. It is recommended that you do not send any material through the Server directly as it may interfere with the HTTP protocol, but you may choose to hook events for monitoring purposes.</dd>
<dt><b>public int SessionTimeout</b></dt>
<dd>The time, in seconds, that a session will persist between requests. The default is 600 (10 minutes).</dd>
</dl>
<p><b>Constructors:</b></p>
<dl>
<dt><b>public HttpServer(Server s)</b></dt>
<dd>Creates a new HttpServer, which will begin processing connections made to the Server s. The server should not be using encryption.</dd>
</dl>
<p><b>Methods:</b></p>
<dl>
<dt><b>public string GetFilename(HttpRequest req)</b></dt>
<dd>Retrieves the file name that matches the document requested in the request. If the host of the request is in Hostmap, that folder is used, otherwise the default folder (webhome) is used.</dd>
<dt><b>protected virtual bool Process(ClientInfo ci, HttpRequest req)</b></dt>
<dd>Provides the default processing for a request, which is to proceed through all entries in Handlers (from the latest to the earliest) asking each handler if it can process the request.</dd>
<dt><b>public Session RequestSession(HttpRequest req)</b></dt>
<dd>Requests that a session be allocated for this request, which will be retained for all subsequent requests from the same user until the session times out.</dd>
</dl>
<hr>
<h3><a name="HttpRequest">HttpRequest class</a></h3>
<p>This class encapsulates the request that the user made. It is effectively a 'reference struct', containing only data.</p>
<p><b>Fields:</b></p>
<dl>
<dt><b>public string Method, Url, Page, HttpVersion, QueryString</b></dt>
<dd>These fields correspond to the first line of the HTTP header which the user sends:
<br><tt>GET /members/info.html?user=17 HTTP/1.1</tt>
<br>In this case Method would be 'GET', Url would be '/members/info.html?user=17', Page would be '/members/info.html', QueryString would be 'user=17' and HttpVersion would be '1.1'. The Query field is a better way to access the query in most cases.</dd>
<dt><b>public string Host</b></dt>
<dd>The Host entry in the HTTP header; which server the user placed in the URL.</dd>
<dt><b>public string Content</b></dt>
<dd>The body, if any, of the request. In the case of a POST submission from a form, this is parsed into the Query.</dd>
<dt><b>public string HeaderText</b></dt>
<dd>The entire text that makes up the HTTP header.</dd>
<dt><b>public Hashtable Cookies</b></dt>
<dd>Any cookies which were passed by the user's browser.</dd>
<dt><b>public Hashtable Header</b></dt>
<dd>The fields which were included in the HTTP header, keyed on the word before the colon in each case.</dd>
<dt><b>public Hashtable Query</b></dt>
<dd>If a query string of the form 'name1=value1&name2=value2&...' was included via the URL and/or POST content, it will be parsed into this map, keyed on the name.</dd>
<dt><b>public bool GotHeader</b></dt>
<dd>Whether the header has yet been completely read. This should always be true in a request handler.</dd>
<dt><b>public IPAddress From</b></dt>
<dd>The source of the request.</dd>
<dt><b>public <a href="#Session">Session</a> Session</b></dt>
<dd>The session associated with this user, if one has been requested.</dd>
<dt><b>public int ContentLength, BytesRead</b></dt>
<dd>The declared length of the content, and the number of bytes read. These two values should be the same in a request handler.</dd>
</dl>
<hr>
<h3><a name="HttpResponse">HttpResponse class</a></h3>
<p>This class defines the response to be sent to the user. Like a request, a response is mostly data which is stored directly in fields, which your application should set.</p>
<p><b>Fields:</b></p>
<dl>
<dt><b>public int ReturnCode</b></dt>
<dd>The HTTP return code that will be sent to the client. The default is 200 (OK); you will need to set this field if there is a problem, typically to 4xx (error with the request) or 5xx (server problem)</dd>
<dt><b>public Hashtable Header</b></dt>
<dd>The extra fields which you wish to be included in the HTTP header, beyond those specified each time.</dd>
<dt><b>public byte[] RawContent
<br>public string Content</b></dt>
<dd>The content of the response. If you are sending binary data, set RawContent; the bytes you specify will be sent with no encoding. If you are sending text, set Content; the text will be sent with an encoding of utf-8.</dd>
<dt><b>public string Url</b></dt>
<dd>The address used to obtain this response. By default this is the same as the Url in the HttpRequest used to request a page.</dd>
</dl>
<p><b>Constructor:</b></p>
<dl>
<dt><b>public HttpResponse()
<br>public HttpResponse(int code, string content)</b></dt>
<dd>Creates a new response. The default code is 200, and the default content is null. You will not need to call the constructor if you are creating a request handler, as a new instance of HttpResponse is provided for you in the argument to Process.</dd>
</dl>
<p><b>Methods:</b></p>
<dl>
<dt><b>public void MakeRedirect(string newurl)</b></dt>
<dd>Makes this response into a redirection (HTTP 303) to the specified other page.</dd>
</dl>
<hr>
<h3><a name="IHttpHandler">IHttpHandler interface</a></h3>
<p>This interface defines a request handler, which is used to create a response when a request is received.</p>
<p><b>Methods:</b></p>
<dl>
<dt><b>bool Process(HttpServer server, HttpRequest request, HttpResponse response)</b></dt>
<dd>Process a request. Your class should assign values to the fields in response, and should use the fields in request to determine what action to take. If you have handled the request (whether successfully or producing an error), you should return true.</dd>
</dl>
<hr>
<h3><a name="Session">Session class</a></h3>
<p>This class provides a container for state information to be kept with a user.</p>
<p><b>Properties:</b></p>
<dl>
<dt><b>public string ID</b> (read only)</dt>
<dd>A unique string which can be used to identify this session.</dd>
<dt><b>public DateTime LastTouched</b> (read only)</dt>
<dd>The time at which this session was last touched.</dd>
<dt><b>public IPAddress User</b> (read only)</dt>
<dd>The IP address for which this session is valid. (Sessions are only valid from their source IP to prevent session hijacking.)</dd>
<dt><b>public object this[object key]</b></dt>
<dd>Saves or retriev
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Embedded .Net HTTP Server.zip (2个子文件)
HTTP.htm 10KB
HTTP.cs 15KB
共 2 条
- 1
资源评论
领君2018
- 粉丝: 204
- 资源: 1527
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功