Exemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();

            var domain   = "http://localhost:8888/";
            var routings = new string[]
            {
                domain
            };

            var helloWorldMiddleware = new HelloWorldMiddeware("/helloworld");
            var weatherMiddeware     = new WeatherMiddleware("/weather");

            helloWorldMiddleware.LinkWith(weatherMiddeware);
            httpServer = new CustomHttpServer(routings, helloWorldMiddleware);
            task       = new Task(async() => await httpServer.Listen());
            task.Start();

            LogMsg("HttpServer was stated for listening ...");
            LogMsg(string.Format("Domain: {0}", domain));
            LogMsg("Endpoints:");
            LogMsg("1) helloworld");
            LogMsg("2) weather");
            LogMsg("Try in browser:");
            LogMsg(string.Format("1) {0}helloworld", domain));
            LogMsg(string.Format("2) {0}weather", domain));
        }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     try
     {
         var server = new CustomHttpServer(8080);
         server.Listen();
     }
     catch (Exception ex)
     {
         var i = "";
     }
 }
Exemplo n.º 3
0
		public virtual long SmartServeFile(ContextRFC AContext, HttpRequestInfo ARequestInfo, string AFile, CustomHttpServer server)
	  {
	    DateTime LFileDate = File.GetLastWriteTime(AFile);
			DateTime LReqDate = Http.GmtToLocalDateTime(ARequestInfo.RawHeaders["If-Modified-Since"]);
	    if (LReqDate.Ticks > 0
	      &&LReqDate.Subtract(new TimeSpan(LFileDate.Ticks)).Ticks < 20000)
      {
        ResponseNo = 304;
        return 0;
      }
      else
      {
          return ServeFile(AContext, AFile, server);
      }
	  }
Exemplo n.º 4
0
		public virtual long ServeFile(ContextRFC AContext, string AFile, CustomHttpServer server)
	  {
	    if (ContentType.Length == 0)
	    {
            ContentType = server.MimeTable.GetFileMIMEType(AFile);
	    }
      ContentLength = (int)new FileInfo(AFile).Length;
	    Date = File.GetLastWriteTime(AFile);
	    WriteHeader();
      AContext.TcpConnection.Socket.WriteFile(AFile);
      return ContentLength;
	  }