Пример #1
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            string resource = GetParam(path);

            //m_log.DebugFormat("[Wifi]: resource {0}", resource);
            resource = resource.Trim(WifiUtils.DirectorySeparatorChars);
            string resourcePath = System.IO.Path.Combine(m_LocalPath, resource);

            resourcePath = Uri.UnescapeDataString(resourcePath);

            string type = WifiUtils.GetContentType(resource);

            httpResponse.ContentType = type;
            //m_log.DebugFormat("[Wifi]: ContentType {0}", type);
            if (type.StartsWith("image"))
            {
                return(WifiUtils.ReadBinaryResource(resourcePath));
            }

            if (type.StartsWith("application") || type.StartsWith("text"))
            {
                string res = WifiUtils.ReadTextResource(resourcePath, true);
                return(WifiUtils.StringToBytes(res));
            }

            m_log.WarnFormat("[Wifi]: Could not find resource {0} in local path {1}", resource, m_LocalPath);
            httpResponse.ContentType = "text/plain";
            string result = "Boo!";

            return(WifiUtils.StringToBytes(result));
        }
Пример #2
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);

            string resource = GetParam(path);

            //m_log.DebugFormat("[Wifi]: resource {0}", resource);
            resource = Uri.UnescapeDataString(resource).Trim(WifiUtils.DirectorySeparatorChars);

            Request request = WifiUtils.CreateRequest(resource, httpRequest);

            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            if (resource == string.Empty || resource.StartsWith("index."))
            {
                if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                {
                    m_WebApp.Services.ComputeStatistics();
                }

                httpResponse.ContentType = "text/html";

                return(WifiUtils.StringToBytes(m_WebApp.Services.DefaultRequest(env)));
            }
            else
            {
                string resourcePath = System.IO.Path.Combine(WifiUtils.DocsPath, resource);
                string type         = WifiUtils.GetContentType(resource);
                httpResponse.ContentType = type;
                //m_log.DebugFormat("[Wifi]: ContentType {0}", type);
                if (type.StartsWith("image"))
                {
                    return(WifiUtils.ReadBinaryResource(resourcePath));
                }

                if (type.StartsWith("application"))
                {
                    string res = WifiUtils.ReadTextResource(resourcePath, true);
                    return(WifiUtils.StringToBytes(res));
                }
                if (type.StartsWith("text"))
                {
                    if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                    {
                        m_WebApp.Services.ComputeStatistics();
                    }

                    resourcePath = Localization.LocalizePath(env, resource);
                    Processor p   = new Processor(m_WebApp.WifiScriptFace, env);
                    string    res = p.Process(WifiUtils.ReadTextResource(resourcePath));
                    if (res == string.Empty)
                    {
                        res = m_WebApp.Services.DefaultRequest(env);
                    }
                    return(WifiUtils.StringToBytes(res));
                }
            }

            httpResponse.ContentType = "text/plain";
            string result = "Boo!";

            return(WifiUtils.StringToBytes(result));
        }