예제 #1
0
        private void ServerOnHandleGet(SimpleHttpProcessor httpProcessor)
        {
            var session = GetSession(httpProcessor);
            var header  = new Dictionary <string, string> {
                { "Cookie", "StonehengeSession=" + session.Id }
            };

            if (httpProcessor.Url == "/")
            {
                httpProcessor.WriteRedirect("/Index.html?stonehenge-id=" + session.Id, header);
                return;
            }

            var resourceName = httpProcessor.Url.Substring(1);
            var parameters   = new Dictionary <string, string>(); //TODO: extract parameters from URL
            var content      = _resourceLoader.Get(session, resourceName, parameters);

            if (content == null)
            {
                httpProcessor.WriteNotFound();
                return;
            }
            if (content.IsBinary)
            {
                header.Add("Content-Length", content.Data.Length.ToString());
                httpProcessor.WriteSuccess(content.ContentType, header);
                httpProcessor.WriteContent(content.Data);
            }
            else
            {
                httpProcessor.WriteSuccess(content.ContentType, header);
                httpProcessor.WriteContent(content.Text);
            }
        }