private void WriteFile(string path, bool tail, HttpListenerContext context) { try { if (tail) { Logger.Debug("Directory server tailing file '{0}'", path); string mimeType = DetectContentType(path); context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK; context.Response.ContentType = mimeType; StreamHandler streamHandler = new StreamHandler(path, TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(this.streamingTimeout), context); streamHandler.Start(); } else { DumpFile(path, context); } } catch (Exception ex) { DirectoryServer.WriteServerError(ex.Message, context); } }
/// <summary> /// If validation with the DEA is successful, the HTTP request is served. /// Otherwise, the same HTTP response from the DEA is served as response to /// the HTTP request. /// </summary> /// <param name="listenerContext">Http context to respond to.</param> private void ServeHttp(object listenerContext) { try { HttpListenerContext context = (HttpListenerContext)listenerContext; Uri uri = context.Request.Url; PathLookupResponse response = this.deaClient.LookupPath(uri); if (!string.IsNullOrWhiteSpace(response.Error)) { Logger.Warning(Strings.ErrorInLookupPath, response.Error); DirectoryServer.WriteServerError(Strings.WinDEADidNotRespondProperly, context); } else { var queryString = string.Join(string.Empty, uri.PathAndQuery.Split('?').Skip(1)); NameValueCollection queryStrings = System.Web.HttpUtility.ParseQueryString(queryString); bool tail = queryStrings.AllKeys.Select(key => queryStrings.GetValues(key).Contains("tail")).Any(v => v); Logger.Debug("Directory Server file request is: {0}; path is {1}", uri, queryStrings["path"]); this.ListPath(response.Path, tail, context); } } catch (Exception ex) { Logger.Error("Directory Server - there was an error serving http: {0}", ex.ToString()); } }