Example #1
0
        private void ExecHttpRequest(Utf8TcpPeer peer, List <string> httpdata)
        {
            try
            {
                if (Authenticator != null)
                {
                    string authstr    = httpdata.FirstOrDefault(s => s.StartsWith("Authorization:"));
                    bool   authorized = false;

                    if (authstr != null)
                    {
                        string user, password;
                        ParseAuthenticationString(authstr, out user, out password);
                        authorized = Authenticator(user, password);
                    }

                    if (!authorized)
                    {
                        SendHttp(peer, "401 Not Authorized", "text/html", ERROR_401, "WWW-Authenticate: Basic realm=\"moonsharp-remote-debugger\"");
                        return;
                    }
                }

                HttpResource res = GetResourceFromPath(httpdata[0]);

                if (res == null)
                {
                    SendHttp(peer, "404 Not Found", "text/html", ERROR_404);
                }
                else
                {
                    SendHttp(peer, "200 OK", res.GetContentTypeString(), res.Data);
                }
            }
            catch (Exception ex)
            {
                m_Server.Logger(ex.Message);

                try
                {
                    SendHttp(peer, "500 Internal Server Error", "text/html", ERROR_500);
                }
                catch (Exception ex2)
                {
                    m_Server.Logger(ex2.Message);
                }
            }
        }