Ejemplo n.º 1
0
        /// <summary>
        /// Process request and send output to client
        /// </summary>
        /// <param name="client">client to send output to</param>
        /// <param name="headers">dictionary of headers</param>
        /// <param name="request">the requested method</param>
        /// <param name="requestUrl">url to respond to</param>
        private void SendOutputToClient(IgbTcpClient client, Dictionary <string, string> headers, string request, string requestUrl)
        {
            using (MemoryStream ms = new MemoryStream())
                using (StreamWriter sw = new StreamWriter(ms))
                {
                    ProcessRequest(request, requestUrl, headers, sw);

                    sw.Flush();
                    ms.Seek(0, SeekOrigin.Begin);

                    // We should support only the "GET" method
                    client.Write(request.Equals("GET") ? "HTTP/1.1 200 OK\n" : "HTTP/1.1 501 Not Implemented\n");
                    client.Write("Server: EVEMon/1.0\n");
                    client.Write("Content-Type: text/html; charset=utf-8\n");
                    if (headers.ContainsKey("eve_trusted") && headers["eve_trusted"].ToLower(CultureConstants.DefaultCulture) == "no")
                    {
                        client.Write("eve.trustme: http://" + BuildHostAndPort(headers["host"]) + "/::EVEMon needs your pilot information.\n");
                    }
                    client.Write("Connection: close\n");
                    client.Write("Content-Length: " + ms.Length.ToString() + "\n\n");
                    using (StreamReader sr = new StreamReader(ms))
                    {
                        client.Write(sr.ReadToEnd());
                    }
                }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Process request and send output to client.
        /// </summary>
        /// <param name="client">client to send output to</param>
        /// <param name="headers">dictionary of headers</param>
        /// <param name="request">the requested method</param>
        /// <param name="requestPath">url to respond to</param>
        private void SendOutputToClient(IgbTcpClient client, IDictionary <string, string> headers, string request,
                                        string requestPath)
        {
            MemoryStream stream = Util.GetMemoryStream();

            using (StreamWriter sw = new StreamWriter(stream))
            {
                ProcessRequest(request, requestPath, headers, sw);

                sw.Flush();
                stream.Seek(0, SeekOrigin.Begin);

                // We should support only the "GET" method
                string responseStatusCode = request.Equals(HttpMethod.Get.Method)
                    ? $"{(int)HttpStatusCode.OK} {HttpStatusCode.OK.ToString().ConvertUpperCamelCaseToString()}"
                    : $"{(int)HttpStatusCode.NotImplemented} {HttpStatusCode.NotImplemented.ToString().ConvertUpperCamelCaseToString()}";
                client.Write($"HTTP/1.1 {responseStatusCode}\n");
                client.Write("Server: EVEMon/1.0\n");
                client.Write("Content-Type: text/html; charset=utf-8\n");
                if (headers.ContainsKey("eve_trusted") &&
                    headers["eve_trusted"].ToLower(CultureConstants.InvariantCulture) == "no")
                {
                    client.Write($"eve.trustme: {BuildHostAndPort(headers["host"])}/::EVEMon needs your character information.\n");
                }

                client.Write("Connection: close\n");
                client.Write($"Content-Length: {stream.Length}\n\n");

                StreamReader sr = new StreamReader(stream);
                client.Write(sr.ReadToEnd());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Process request and send output to client.
        /// </summary>
        /// <param name="client">client to send output to</param>
        /// <param name="headers">dictionary of headers</param>
        /// <param name="request">the requested method</param>
        /// <param name="requestPath">url to respond to</param>
        private void SendOutputToClient(IgbTcpClient client, IDictionary<string, string> headers, string request,
            string requestPath)
        {
            MemoryStream stream = Util.GetMemoryStream();
            using (StreamWriter sw = new StreamWriter(stream))
            {
                ProcessRequest(request, requestPath, headers, sw);

                sw.Flush();
                stream.Seek(0, SeekOrigin.Begin);

                // We should support only the "GET" method
                string responseStatusCode = request.Equals(HttpMethod.Get.Method)
                    ? $"{(int)HttpStatusCode.OK} {HttpStatusCode.OK.ToString().ConvertUpperCamelCaseToString()}"
                    : $"{(int)HttpStatusCode.NotImplemented} {HttpStatusCode.NotImplemented.ToString().ConvertUpperCamelCaseToString()}";
                client.Write($"HTTP/1.1 {responseStatusCode}\n");
                client.Write("Server: EVEMon/1.0\n");
                client.Write("Content-Type: text/html; charset=utf-8\n");
                if (headers.ContainsKey("eve_trusted") &&
                    headers["eve_trusted"].ToLower(CultureConstants.InvariantCulture) == "no")
                {
                    client.Write($"eve.trustme: {BuildHostAndPort(headers["host"])}/::EVEMon needs your character information.\n");
                }

                client.Write("Connection: close\n");
                client.Write($"Content-Length: {stream.Length}\n\n");

                StreamReader sr = new StreamReader(stream);
                client.Write(sr.ReadToEnd());
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Process request and send output to client
        /// </summary>
        /// <param name="client">client to send output to</param>
        /// <param name="headers">dictionary of headers</param>
        /// <param name="request">the requested method</param>
        /// <param name="requestUrl">url to respond to</param>
        private void SendOutputToClient(IgbTcpClient client, Dictionary<string, string> headers, string request, string requestUrl)
        {
            using (MemoryStream ms = new MemoryStream())
            using (StreamWriter sw = new StreamWriter(ms))
            {
                ProcessRequest(request, requestUrl, headers, sw);

                sw.Flush();
                ms.Seek(0, SeekOrigin.Begin);

                // We should support only the "GET" method
                client.Write(request.Equals("GET") ? "HTTP/1.1 200 OK\n" : "HTTP/1.1 501 Not Implemented\n");
                client.Write("Server: EVEMon/1.0\n");
                client.Write("Content-Type: text/html; charset=utf-8\n");
                if (headers.ContainsKey("eve_trusted") && headers["eve_trusted"].ToLower(CultureConstants.DefaultCulture) == "no")
                {
                    client.Write("eve.trustme: http://" + BuildHostAndPort(headers["host"]) + "/::EVEMon needs your pilot information.\n");
                }
                client.Write("Connection: close\n");
                client.Write("Content-Length: " + ms.Length.ToString() + "\n\n");
                using (StreamReader sr = new StreamReader(ms))
                {
                    client.Write(sr.ReadToEnd());
                }
            }
        }