annotate Net/HTTP.cs @ 54:ba4e2cb031e0

Added general purpose tar archive reader class
author Ivo Smits <Ivo@UCIS.nl>
date Wed, 02 Oct 2013 21:17:30 +0200
parents 8df7f4dc5615
children 50d4aed66c67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
1 ???using System;
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
2 using System.Collections.Generic;
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
3 using System.IO;
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
4 using System.Net;
10
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
5 using System.Net.Security;
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
6 using System.Net.Sockets;
10
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
7 using System.Security.Cryptography.X509Certificates;
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
8 using System.Text;
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
9 using UCIS.Net;
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
10 using UCIS.Util;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
11 using HTTPHeader = System.Collections.Generic.KeyValuePair<string, string>;
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
12
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
13 namespace UCIS.Net.HTTP {
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
14 public class HTTPServer : TCPServer.IModule, IDisposable {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
15 public IHTTPContentProvider ContentProvider { get; set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
16 public Boolean ServeFlashPolicyFile { get; set; }
10
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
17 public X509Certificate SSLCertificate { get; set; }
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
18 private Socket Listener = null;
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
19
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
20 public HTTPServer() { }
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
21
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
22 public void Listen(int port) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
23 Listen(new IPEndPoint(IPAddress.Any, port));
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
24 }
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
25
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
26 public void Listen(EndPoint localep) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
27 if (Listener != null) throw new InvalidOperationException("A listener exists");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
28 Listener = new Socket(localep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
29 Listener.Bind(localep);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
30 Listener.Listen(5);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
31 Listener.BeginAccept(AcceptCallback, null);
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
32 }
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
33
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
34 private void AcceptCallback(IAsyncResult ar) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
35 try {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
36 Socket socket = Listener.EndAccept(ar);
10
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
37 if (SSLCertificate != null) {
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
38 SslStream ssl = new SslStream(new NetworkStream(socket, true));
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
39 ssl.BeginAuthenticateAsServer(SSLCertificate, SslAuthenticationCallback, new Object[] { socket, ssl });
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
40 } else {
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
41 new HTTPContext(this, socket);
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
42 }
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
43 } catch (Exception) { }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
44 try {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
45 Listener.BeginAccept(AcceptCallback, null);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
46 } catch (Exception) { }
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
47 }
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
48
10
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
49 private void SslAuthenticationCallback(IAsyncResult ar) {
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
50 Object[] args = (Object[])ar.AsyncState;
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
51 Socket socket = (Socket)args[0];
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
52 SslStream ssl = (SslStream)args[1];
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
53 try {
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
54 ssl.EndAuthenticateAsServer(ar);
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
55 new HTTPContext(this, ssl, socket);
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
56 } catch (Exception) { }
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
57 }
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
58
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
59 public void Dispose() {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
60 if (Listener != null) Listener.Close();
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
61 }
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
62
45
8df7f4dc5615 HTTP Server: enable KeepAlive option on TCP sockets
Ivo Smits <Ivo@UCIS.nl>
parents: 16
diff changeset
63 public void HandleClient(Socket client) {
8df7f4dc5615 HTTP Server: enable KeepAlive option on TCP sockets
Ivo Smits <Ivo@UCIS.nl>
parents: 16
diff changeset
64 new HTTPContext(this, client);
8df7f4dc5615 HTTP Server: enable KeepAlive option on TCP sockets
Ivo Smits <Ivo@UCIS.nl>
parents: 16
diff changeset
65 }
8df7f4dc5615 HTTP Server: enable KeepAlive option on TCP sockets
Ivo Smits <Ivo@UCIS.nl>
parents: 16
diff changeset
66
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
67 bool TCPServer.IModule.Accept(TCPStream stream) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
68 new HTTPContext(this, stream);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
69 return false;
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
70 }
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
71 }
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
72
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
73 public class HTTPContext {
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
74 public HTTPServer Server { get; private set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
75 public EndPoint LocalEndPoint { get; private set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
76 public EndPoint RemoteEndPoint { get; private set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
77
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
78 public String RequestMethod { get; private set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
79 public String RequestPath { get; private set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
80 public String RequestQuery { get; private set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
81 public int HTTPVersion { get; set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
82
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
83 public Socket Socket { get; private set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
84 public Boolean SuppressStandardHeaders { get; set; }
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
85 public TCPStream TCPStream { get; private set; }
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
86
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
87 private StreamWriter Writer;
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
88 private PrebufferingStream Reader;
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
89 private List<HTTPHeader> RequestHeaders;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
90 private HTTPConnectionState State = HTTPConnectionState.Starting;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
91
10
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
92
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
93 private enum HTTPConnectionState {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
94 Starting = 0,
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
95 ReceivingRequest = 1,
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
96 ProcessingRequest = 2,
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
97 SendingHeaders = 3,
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
98 SendingContent = 4,
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
99 Closed = 5,
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
100 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
101
10
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
102 public HTTPContext(HTTPServer server, TCPStream stream) : this(server, stream, stream.Socket) { }
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
103 public HTTPContext(HTTPServer server, Socket socket) : this(server, null, socket) { }
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
104 public HTTPContext(HTTPServer server, Stream stream, Socket socket) {
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
105 this.Server = server;
10
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
106 this.Socket = socket;
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
107 if (socket != null) {
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
108 this.LocalEndPoint = socket.LocalEndPoint;
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
109 this.RemoteEndPoint = socket.RemoteEndPoint;
45
8df7f4dc5615 HTTP Server: enable KeepAlive option on TCP sockets
Ivo Smits <Ivo@UCIS.nl>
parents: 16
diff changeset
110 if (socket.ProtocolType == ProtocolType.Tcp) socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
10
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
111 if (stream == null) stream = new NetworkStream(socket, true);
7269e91c6e26 HTTPServer: added support for HTTPS
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
112 }
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
113 Init(stream);
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
114 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
115
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
116 private void Init(Stream Stream) {
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
117 Writer = new StreamWriter(Stream, Encoding.ASCII);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
118 Writer.NewLine = "\r\n";
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
119 Writer.AutoFlush = true;
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
120 Reader = new PrebufferingStream(Stream);
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
121 Reader.BeginPrebuffering(PrebufferCallback, null);
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
122 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
123
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
124 private String ReadLine() {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
125 StringBuilder s = new StringBuilder();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
126 while (true) {
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
127 int b = Reader.ReadByte();
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
128 if (b == -1) {
4
9e2e6433f57a Small fix for HTTP Server - Flash Cross Domain Policy File support
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
129 if (s.Length == 0) return null;
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
130 break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
131 } else if (b == 13) {
4
9e2e6433f57a Small fix for HTTP Server - Flash Cross Domain Policy File support
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
132 } else if (b == 10 || b == 0) {
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
133 break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
134 } else {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
135 s.Append((Char)b);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
136 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
137 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
138 return s.ToString();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
139 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
140
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
141 private void PrebufferCallback(IAsyncResult ar) {
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
142 State = HTTPConnectionState.ReceivingRequest;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
143 try {
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
144 Reader.EndPrebuffering(ar);
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
145 String line = ReadLine();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
146 if (line == null) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
147 Close();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
148 return;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
149 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
150 if (Server.ServeFlashPolicyFile && line[0] == '<') { //<policy-file-request/>
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
151 Writer.WriteLine("<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>");
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
152 Reader.WriteByte(0);
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
153 Close();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
154 return;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
155 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
156 String[] request = line.Split(' ');
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
157 if (request.Length != 3) goto SendError400AndClose;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
158 RequestMethod = request[0];
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
159 String RequestAddress = request[1];
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
160 switch (request[2]) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
161 case "HTTP/1.0": HTTPVersion = 10; break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
162 case "HTTP/1.1": HTTPVersion = 11; break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
163 default: goto SendError400AndClose;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
164 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
165 request = RequestAddress.Split(new Char[] { '?' });
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
166 RequestPath = Uri.UnescapeDataString(request[0]);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
167 RequestQuery = request.Length > 1 ? request[1] : null;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
168 RequestHeaders = new List<HTTPHeader>();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
169 while (true) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
170 line = ReadLine();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
171 if (line == null) goto SendError400AndClose;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
172 if (line.Length == 0) break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
173 request = line.Split(new String[] { ": " }, 2, StringSplitOptions.None);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
174 if (request.Length != 2) goto SendError400AndClose;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
175 RequestHeaders.Add(new HTTPHeader(request[0], request[1]));
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
176 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
177 IHTTPContentProvider content = Server.ContentProvider;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
178 if (content == null) goto SendError500AndClose;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
179 State = HTTPConnectionState.ProcessingRequest;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
180 content.ServeRequest(this);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
181 } catch (Exception ex) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
182 Console.Error.WriteLine(ex);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
183 switch (State) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
184 case HTTPConnectionState.ProcessingRequest: goto SendError500AndClose;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
185 default:
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
186 Close();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
187 break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
188 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
189 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
190 return;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
191
54
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
192 SendError400AndClose:
7
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
193 State = HTTPConnectionState.ProcessingRequest;
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
194 SendErrorAndClose(400);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
195 return;
54
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
196 SendError500AndClose:
7
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
197 State = HTTPConnectionState.ProcessingRequest;
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
198 SendErrorAndClose(500);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
199 return;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
200 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
201
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
202 public String GetRequestHeader(String name) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
203 if (State != HTTPConnectionState.ProcessingRequest && State != HTTPConnectionState.SendingHeaders && State != HTTPConnectionState.SendingContent) throw new InvalidOperationException();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
204 foreach (HTTPHeader h in RequestHeaders) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
205 if (name.Equals(h.Key, StringComparison.OrdinalIgnoreCase)) return h.Value;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
206 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
207 return null;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
208 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
209 public String[] GetRequestHeaders(String name) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
210 if (State != HTTPConnectionState.ProcessingRequest && State != HTTPConnectionState.SendingHeaders && State != HTTPConnectionState.SendingContent) throw new InvalidOperationException();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
211 String[] items = new String[0];
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
212 foreach (HTTPHeader h in RequestHeaders) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
213 if (name.Equals(h.Key, StringComparison.OrdinalIgnoreCase)) ArrayUtil.Add(ref items, h.Value);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
214 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
215 return items;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
216 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
217
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
218 public void SendErrorAndClose(int state) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
219 try {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
220 SendStatus(state);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
221 GetResponseStream();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
222 } catch (Exception ex) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
223 Console.Error.WriteLine(ex);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
224 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
225 Close();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
226 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
227
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
228 public void SendStatus(int code) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
229 String message;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
230 switch (code) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
231 case 101: message = "Switching Protocols"; break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
232 case 200: message = "OK"; break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
233 case 400: message = "Bad Request"; break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
234 case 404: message = "Not Found"; break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
235 case 500: message = "Internal Server Error"; break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
236 default: message = "Unknown Status"; break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
237 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
238 SendStatus(code, message);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
239 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
240 public void SendStatus(int code, String message) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
241 if (State != HTTPConnectionState.ProcessingRequest) throw new InvalidOperationException();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
242 StringBuilder sb = new StringBuilder();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
243 sb.Append("HTTP/");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
244 switch (HTTPVersion) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
245 case 10: sb.Append("1.0"); break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
246 case 11: sb.Append("1.1"); break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
247 default: throw new ArgumentException("The HTTP version is not supported", "HTTPVersion");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
248 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
249 sb.Append(" ");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
250 sb.Append(code);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
251 sb.Append(" ");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
252 sb.Append(message);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
253 Writer.WriteLine(sb.ToString());
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
254 State = HTTPConnectionState.SendingHeaders;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
255 if (!SuppressStandardHeaders) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
256 SendHeader("Expires", "Expires: Sun, 1 Jan 2000 00:00:00 GMT");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
257 SendHeader("Cache-Control", "no-store, no-cache, must-revalidate");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
258 SendHeader("Cache-Control", "post-check=0, pre-check=0");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
259 SendHeader("Pragma", "no-cache");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
260 SendHeader("Server", "UCIS Webserver");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
261 SendHeader("Connection", "Close");
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
262 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
263 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
264 public void SendHeader(String name, String value) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
265 if (State == HTTPConnectionState.ProcessingRequest) SendStatus(200);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
266 if (State != HTTPConnectionState.SendingHeaders) throw new InvalidOperationException();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
267 Writer.WriteLine(name + ": " + value);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
268 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
269 public Stream GetResponseStream() {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
270 if (State == HTTPConnectionState.ProcessingRequest) SendStatus(200);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
271 if (State == HTTPConnectionState.SendingHeaders) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
272 Writer.WriteLine();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
273 State = HTTPConnectionState.SendingContent;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
274 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
275 if (State != HTTPConnectionState.SendingContent) throw new InvalidOperationException();
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
276 return Reader;
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
277 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
278
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
279 public void Close() {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
280 if (State == HTTPConnectionState.Closed) return;
6
5ce7a138fdba Improvements in HTTP server
Ivo Smits <Ivo@UCIS.nl>
parents: 4
diff changeset
281 Reader.Close();
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
282 State = HTTPConnectionState.Closed;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
283 }
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
284 }
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
285
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
286 public interface IHTTPContentProvider {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
287 void ServeRequest(HTTPContext context);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
288 }
12
ba8f94212c6e Added WebSocket support
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
289 public delegate void HTTPContentProviderDelegate(HTTPContext context);
ba8f94212c6e Added WebSocket support
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
290 public class HTTPContentProviderFunction : IHTTPContentProvider {
ba8f94212c6e Added WebSocket support
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
291 public HTTPContentProviderDelegate Handler { get; private set; }
ba8f94212c6e Added WebSocket support
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
292 public HTTPContentProviderFunction(HTTPContentProviderDelegate handler) {
ba8f94212c6e Added WebSocket support
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
293 this.Handler = handler;
ba8f94212c6e Added WebSocket support
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
294 }
ba8f94212c6e Added WebSocket support
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
295 public void ServeRequest(HTTPContext context) {
ba8f94212c6e Added WebSocket support
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
296 Handler(context);
ba8f94212c6e Added WebSocket support
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
297 }
ba8f94212c6e Added WebSocket support
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
298 }
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
299 public class HTTPPathSelector : IHTTPContentProvider {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
300 private List<KeyValuePair<String, IHTTPContentProvider>> Prefixes;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
301 private StringComparison PrefixComparison;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
302 public HTTPPathSelector() : this(false) { }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
303 public HTTPPathSelector(Boolean caseSensitive) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
304 Prefixes = new List<KeyValuePair<string, IHTTPContentProvider>>();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
305 PrefixComparison = caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
306 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
307 public void AddPrefix(String prefix, IHTTPContentProvider contentProvider) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
308 Prefixes.Add(new KeyValuePair<string, IHTTPContentProvider>(prefix, contentProvider));
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
309 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
310 public void DeletePrefix(String prefix) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
311 Prefixes.RemoveAll(delegate(KeyValuePair<string, IHTTPContentProvider> item) { return prefix.Equals(item.Key, PrefixComparison); });
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
312 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
313 public void ServeRequest(HTTPContext context) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
314 KeyValuePair<string, IHTTPContentProvider> c = Prefixes.Find(delegate(KeyValuePair<string, IHTTPContentProvider> item) { return context.RequestPath.StartsWith(item.Key, PrefixComparison); });
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
315 if (c.Value != null) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
316 c.Value.ServeRequest(context);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
317 } else {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
318 context.SendErrorAndClose(404);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
319 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
320 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
321 }
7
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
322 public class HTTPStaticContent : IHTTPContentProvider {
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
323 public ArraySegment<Byte> ContentBuffer { get; set; }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
324 public String ContentType { get; set; }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
325 public HTTPStaticContent() : this(new ArraySegment<Byte>()) { }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
326 public HTTPStaticContent(ArraySegment<Byte> content) : this(content, "application/octet-stream") { }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
327 public HTTPStaticContent(String content, String contentType) : this(Encoding.UTF8.GetBytes(content), contentType) { }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
328 public HTTPStaticContent(String contentType) : this(new ArraySegment<Byte>(), contentType) { }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
329 public HTTPStaticContent(Byte[] content, String contentType) : this(new ArraySegment<Byte>(content), contentType) { }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
330 public HTTPStaticContent(ArraySegment<Byte> content, String contentType) {
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
331 this.ContentBuffer = content;
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
332 this.ContentType = contentType;
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
333 }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
334 public void SetContent(Byte[] bytes) { ContentBuffer = new ArraySegment<byte>(bytes); }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
335 public void SetContent(Byte[] bytes, int offset, int count) { ContentBuffer = new ArraySegment<byte>(bytes, offset, count); }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
336 public void SetContent(String content, Encoding encoding) { SetContent(encoding.GetBytes(content)); }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
337 public void SetContent(String content) { SetContent(content, Encoding.UTF8); }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
338 public void ServeRequest(HTTPContext context) {
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
339 ArraySegment<Byte> content = ContentBuffer;
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
340 if (content.Array == null) {
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
341 context.SendErrorAndClose(404);
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
342 return;
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
343 }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
344 String contentType = ContentType;
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
345 context.SendStatus(200);
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
346 if (contentType != null) context.SendHeader("Content-Type", contentType);
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
347 context.SendHeader("Content-Length", content.Count.ToString());
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
348 Stream response = context.GetResponseStream();
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
349 response.Write(content.Array, content.Offset, content.Count);
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
350 response.Close();
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
351 }
4b78cc5f116b Fixes and improvements (some untested)
Ivo Smits <Ivo@UCIS.nl>
parents: 6
diff changeset
352 }
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
353 public class HTTPFileProvider : IHTTPContentProvider {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
354 public String FileName { get; private set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
355 public String ContentType { get; private set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
356 public HTTPFileProvider(String fileName) : this(fileName, "application/octet-stream") { }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
357 public HTTPFileProvider(String fileName, String contentType) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
358 this.FileName = fileName;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
359 this.ContentType = contentType;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
360 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
361 public void ServeRequest(HTTPContext context) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
362 if (File.Exists(FileName)) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
363 using (FileStream fs = File.OpenRead(FileName)) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
364 context.SendStatus(200);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
365 context.SendHeader("Content-Type", ContentType);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
366 context.SendHeader("Content-Length", fs.Length.ToString());
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
367 long left = fs.Length;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
368 Stream response = context.GetResponseStream();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
369 byte[] buffer = new byte[1024 * 10];
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
370 while (fs.CanRead) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
371 int len = fs.Read(buffer, 0, buffer.Length);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
372 if (len <= 0) break;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
373 left -= len;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
374 response.Write(buffer, 0, len);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
375 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
376 response.Close();
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
377 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
378 } else {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
379 context.SendErrorAndClose(404);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
380 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
381 }
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
382 }
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
383 public class HTTPUnTarchiveProvider : IHTTPContentProvider {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
384 public String TarFileName { get; private set; }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
385 public HTTPUnTarchiveProvider(String tarFile) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
386 this.TarFileName = tarFile;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
387 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
388 public void ServeRequest(HTTPContext context) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
389 if (!File.Exists(TarFileName)) {
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
390 context.SendErrorAndClose(404);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
391 return;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
392 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
393 String reqname1 = context.RequestPath;
54
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
394 if (reqname1.StartsWith("/")) reqname1 = reqname1.Substring(1);
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
395 String reqname2 = reqname1;
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
396 if (reqname2.Length > 0 && !reqname2.EndsWith("/")) reqname2 += "/";
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
397 reqname2 += "index.htm";
54
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
398 foreach (TarchiveEntry file in new TarchiveReader(TarFileName)) {
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
399 if (!file.IsFile) continue;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
400 if (!reqname1.Equals(file.Name, StringComparison.OrdinalIgnoreCase) && !reqname2.Equals(file.Name, StringComparison.OrdinalIgnoreCase)) continue;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
401 context.SendStatus(200);
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
402 context.SendHeader("Content-Length", file.Size.ToString());
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
403 String ctype = null;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
404 switch (Path.GetExtension(file.Name).ToLowerInvariant()) {
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
405 case ".txt": ctype = "text/plain"; break;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
406 case ".htm":
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
407 case ".html": ctype = "text/html"; break;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
408 case ".css": ctype = "text/css"; break;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
409 case ".js": ctype = "application/x-javascript"; break;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
410 case ".png": ctype = "image/png"; break;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
411 case ".jpg":
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
412 case ".jpeg": ctype = "image/jpeg"; break;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
413 case ".gif": ctype = "image/gif"; break;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
414 case ".ico": ctype = "image/x-icon"; break;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
415 }
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
416 if (ctype != null) context.SendHeader("Content-Type", ctype);
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
417 using (Stream response = context.GetResponseStream(), source = file.GetStream()) {
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
418 byte[] buffer = new byte[Math.Min(source.Length, 1024 * 10)];
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
419 while (source.CanRead) {
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
420 int len = source.Read(buffer, 0, buffer.Length);
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
421 if (len <= 0) break;
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
422 response.Write(buffer, 0, len);
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
423 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
424 }
54
ba4e2cb031e0 Added general purpose tar archive reader class
Ivo Smits <Ivo@UCIS.nl>
parents: 45
diff changeset
425 return;
3
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
426 }
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
427 context.SendErrorAndClose(404);
0cc7be03775f Improved HTTP Server components
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
428 }
0
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
429 }
3ab940a0c7a0 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
430 }