Ejemplo n.º 1
0
 /// <summary>
 /// Event handler for open stream.
 /// </summary>
 /// <param name="sender">The sender</param>
 /// <param name="e">Event data</param>
 private static void OnStreamOpened(object sender, StreamEventArgs e)
 {
     Http2Logger.LogConsole("Stream is opened: id=" + e.Stream.StreamId);
     string filename = e.Stream.Headers[ProtocolHeaders.Path];
     lock (exclusiveLock)
     {
         currentStreams.StartStream(filename, e.Stream.StreamId);
     }
 }
        private void session_OnStreamOpened(object sender, StreamEventArgs e)
        {
            string file = e.Stream.Headers[ProtocolHeaders.Path];
            Console.WriteLine("Requested file: " + file);

            if (string.IsNullOrEmpty(file))
            {
                Console.WriteLine("Empty file name in the request");
                e.Stream.Close(StatusCode.RefusedStream);
                return;
            }

            string path = Path.GetFullPath("root" + file);

            if (!File.Exists(path))
            {
                Console.WriteLine("File {0} not found", file);
                e.Stream.Close(StatusCode.RefusedStream);
                return;
            }

            try
            {
                using (StreamReader sr = new StreamReader(path))
                {
                    e.Stream.SendData(new ProtocolData(sr.ReadToEnd()), true);
                    Console.WriteLine("File {0} sent", file);
                }
            }
            finally
            {
                e.Stream.Close();
            }
        }