//thread for running works on the client that we have gathered private static void threadRun(object client) { if (client is TcpClient) { TcpClient tcp = client as TcpClient; CS422.WebRequest req = BuildRequest(tcp); if (req != null) { foreach (WebService w in services) { w.Handler(req); } } else { string message = "Valid HTTP request was not found."; byte[] b = Encoding.ASCII.GetBytes(message); Stream s = tcp.GetStream(); s.Write(b, 0, b.Length); } tcp.GetStream().Close(); tcp.Close(); } }
// Methods public override void Handler(WebRequest request) { Console.WriteLine("Service Handler: OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"); _request = request; // Parse the URI and determine which of the 3 is the case: string[] parsedURI = request.URI.Split('/'); List <string> dirNames = new List <string>(); int count = 0; foreach (string s in parsedURI) { if (count > 1)// so we only have traversable dirnames { Console.WriteLine("adding: " + parsedURI[count]); dirNames.Add(parsedURI[count]); } Console.WriteLine("s: " + s); Console.WriteLine("c: " + count); count++; } Console.WriteLine("dirNames.Count: " + dirNames.Count); Dir422 currentDir = _fs.GetRoot(); Dir422 lastDir; File422 file = null; foreach (string s in dirNames) { if (!String.IsNullOrEmpty(s)) { Console.WriteLine("locating: " + s); lastDir = currentDir; currentDir = currentDir.GetDir(s); if (null == currentDir) // check to see if a file { Console.WriteLine("Null Dir"); file = lastDir.GetFile(s); if (null == file) { Console.WriteLine("Null File"); //requested Resource does not exist // so 404 write to network and return request.WriteNotFoundResponse("Could not find file: " + s + "."); return; } // otherwise write file contents as html WriteFileContents(file); return; } } } // If this point is reached then we should have a dir and // we must write its file listing to the network WriteDirListing(currentDir); // Provide support for partial content responses // (i.e. support the Range header) }
//thread for running works on the client that we have gathered private static void threadRun(object client) { if (client is TcpClient) { TcpClient tcp = client as TcpClient; CS422.WebRequest req = BuildRequest(tcp); if (req != null) { foreach (WebService w in services) { w.Handler(req); } } tcp.GetStream().Close(); tcp.Close(); } }
//Constructor public FilesWebService(FileSys422 fs) { _fs = fs; _request = null; _cwd = new StringBuilder(); }