Пример #1
0
        private void HandlePostRequest(HttpMessage message) {
            string path = message.Path;

            bool? success = null;
            if (String.CompareOrdinal(path, "/log/success") == 0) {
                success = true;
            }
            else if (String.CompareOrdinal(path, "/log/failure") == 0) {
                success = false;
            }

            if (success.HasValue) {
                if (Log != null) {
                    string log = new StreamReader(message.RequestStream).ReadToEnd();

                    WebTestLogEventArgs logEvent = new WebTestLogEventArgs(success.Value, log);
                    Log(this, logEvent);
                }

                message.WriteStatus(HttpStatusCode.NoContent);
                return;
            }

            message.WriteStatus(HttpStatusCode.NotFound);
        }
Пример #2
0
        private void HandleGetRequest(HttpMessage message) {
            string urlPath;
            string path = GetResolvedPath(message.Path, out urlPath);

            Tuple<string, string> content;
            if (_registeredContent.TryGetValue(urlPath, out content)) {
                message.WriteContent(content.Item1, content.Item2);
                return;
            }

            if (File.Exists(path)) {
                message.WriteFile(path, GetContentType(path));
            }
            else {
                message.WriteStatus(HttpStatusCode.NotFound);
            }
        }
Пример #3
0
        private void Run() {
            TcpListener listener = new TcpListener(new IPEndPoint(IPAddress.Loopback, _port));
            listener.Start();

            while (_alive) {
                try {
                    TcpClient client = listener.AcceptTcpClient();

                    HttpMessage message = new HttpMessage(this, _getHandler, _postHandler);
                    message.ProcessClient(client);
                }
                catch {
                }

                Thread.Sleep(1);
            }

            listener.Stop();
        }