コード例 #1
0
        public override byte[] Handle(string path, Stream requestData,
                                      IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
        {
            string resource = GetParam(path);

            resource = resource.Trim(WebAppUtils.DirectorySeparatorChars);
            string resourcePath = System.IO.Path.Combine(m_LocalPath, resource);

            resourcePath = Uri.UnescapeDataString(resourcePath);
            m_log.DebugFormat("[Wifi]: resourcePath {0}", resourcePath);

            string type = WebAppUtils.GetContentType(resource);

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

            if (type.StartsWith("application") || type.StartsWith("text"))
            {
                string res = WebAppUtils.ReadTextResource(new string[] { resourcePath }, WebApp.MissingPage, true);
                return(WebAppUtils.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(WebAppUtils.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(WebAppUtils.DirectorySeparatorChars);

            Request request = RequestFactory.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(WebAppUtils.StringToBytes(m_WebApp.Services.DefaultRequest(env)));
            }
            else
            {
                string resourcePath = System.IO.Path.Combine(WebApp.DocsPath, resource);
                string type         = WebAppUtils.GetContentType(resource);
                httpResponse.ContentType = type;
                //m_log.DebugFormat("[Wifi]: ContentType {0}", type);
                if (type.StartsWith("image"))
                {
                    return(WebAppUtils.ReadBinaryResource(resourcePath));
                }

                if (type.StartsWith("application"))
                {
                    string res = WebAppUtils.ReadTextResource(resourcePath, true);
                    return(WebAppUtils.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(WebAppUtils.ReadTextResource(resourcePath));
                    if (res == string.Empty)
                    {
                        res = m_WebApp.Services.DefaultRequest(env);
                    }
                    return(WebAppUtils.StringToBytes(res));
                }
            }

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

            return(WebAppUtils.StringToBytes(result));
        }