Beispiel #1
0
 public void Execute(HtcHttpContext context)
 {
     foreach (var i in _indexes)
     {
         var index = HttpIoUtils.ReplaceVars(context, i);
         if (index.Equals("$internal_indexes"))
         {
             foreach (var j in UrlMapper.IndexFiles)
             {
                 var indexPath = Path.Combine(context.ServerInfo.RootPath, j[0].Equals('/') ? j.Remove(0, 1) : Path.Combine(context.Request.Path, j).Remove(0, 1));
                 if (!File.Exists(indexPath))
                 {
                     continue;
                 }
                 var extension = Path.GetExtension(indexPath);
                 context.Request.RequestFilePath = indexPath;
                 if (UrlMapper.ExtensionPlugins.TryGetValue(extension.ToLower(), out var plugin))
                 {
                     if (!plugin.OnHttpExtensionRequest(context, indexPath, extension.ToLower()))
                     {
                         continue;
                     }
                     context.ErrorMessageManager.SendError(context, 500);
                     return;
                 }
                 try {
                     HttpIoUtils.CallFile(context, indexPath);
                 } catch {
                     context.ErrorMessageManager.SendError(context, 500);
                 }
                 return;
             }
         }
         else
         {
             var indexPath = Path.Combine(context.ServerInfo.RootPath, index[0].Equals('/') ? index.Remove(0, 1) : Path.Combine(context.Request.Path, index).Remove(0, 1));
             if (!File.Exists(indexPath))
             {
                 continue;
             }
             var extension = Path.GetExtension(indexPath);
             context.Request.RequestFilePath = indexPath;
             if (UrlMapper.ExtensionPlugins.TryGetValue(extension.ToLower(), out var plugin))
             {
                 if (!plugin.OnHttpExtensionRequest(context, indexPath, extension.ToLower()))
                 {
                     continue;
                 }
                 context.ErrorMessageManager.SendError(context, 500);
                 return;
             }
             try {
                 HttpIoUtils.CallFile(context, indexPath);
             } catch {
                 context.ErrorMessageManager.SendError(context, 500);
             }
             return;
         }
     }
 }
Beispiel #2
0
 public void Execute(HtcHttpContext context)
 {
     foreach (var file in _files)
     {
         var tempPath = HttpIoUtils.ReplaceVars(context, file);
         if (tempPath[0].Equals('='))
         {
             if (int.TryParse(tempPath.Remove(0, 1), out var statusCode))
             {
                 context.ErrorMessageManager.SendError(context, statusCode);
                 return;
             }
             context.ErrorMessageManager.SendError(context, 500);
             return;
         }
         if (tempPath[0].Equals('@'))
         {
             foreach (var location in _httpLocationManager.Locations)
             {
                 if (!location.Key.Equals(tempPath, StringComparison.CurrentCultureIgnoreCase))
                 {
                     continue;
                 }
                 location.Execute(context);
                 return;
             }
         }
         context.Request.TranslatedPath = Path.GetFullPath(Path.Combine(context.ServerInfo.RootPath, tempPath.Remove(0, 1)));
         if (File.Exists(context.Request.TranslatedPath))
         {
             var extension = Path.GetExtension(context.Request.TranslatedPath);
             if (UrlMapper.ExtensionPlugins.ContainsKey(extension.ToLower()))
             {
                 if (UrlMapper.ExtensionPlugins[extension.ToLower()].OnHttpExtensionRequest(context, context.Request.TranslatedPath, extension.ToLower()))
                 {
                     context.ErrorMessageManager.SendError(context, 500);
                 }
             }
             else
             {
                 try {
                     HttpIoUtils.CallFile(context, context.Request.TranslatedPath);
                 } catch {
                     context.ErrorMessageManager.SendError(context, 500);
                 }
             }
         }
         else if (Directory.Exists(context.Request.TranslatedPath))
         {
             if (!context.Request.RequestPath.EndsWith('/'))
             {
                 context.Response.Redirect(context.Request.RequestPath + "/");
             }
             //context.ErrorMessageManager.SendError(context, 404);
             // Do indexer
         }
     }
 }
Beispiel #3
0
        public void Execute(HtcHttpContext context)
        {
            var match = _pattern.Match(context.Request.Path);

            if (!match.Success)
            {
                return;
            }
            var newRequest = HttpIoUtils.ReplaceVars(context, _rewriteData);

            for (var i = 0; i < match.Captures.Count; i++)
            {
                newRequest = newRequest.Replace($"${i + 1}", match.Captures[i].Value);
            }

            /*foreach (Match match in _pattern.Matches(context.Request.Path)) {
             *  newRequest = newRequest.Replace($"${match.Name}", match.Value);
             * }*/
            /*var rewriteQuery = _rewriteData.Split("?");
             *  request = rewriteQuery[0].Replace("$scheme", context.Request.Scheme);
             *  if (rewriteQuery.Length == 1) {
             *      request = _rewriteData;
             *      Logger.Info($"{request}");
             *      for (var p = 1; p < requestParts.Length; p++) {
             *          request = request.Replace($"${p}", requestParts[p]);
             *      }
             *      Logger.Info($"{request}");
             *  } else if (rewriteQuery.Length == 2) {
             *      var queryParts = rewriteQuery[1].Split("&");
             *      foreach (var query in queryParts) {
             *          var queryData = query.Split("=");
             *          var key = queryData[0];
             *          var value = queryData[1];
             *          for (var p = 1; p < requestParts.Length; p++) {
             *              value = value.Replace($"${p}", requestParts[p]);
             *          }
             *          context.Request.Query.Add(key, value);
             *      }
             *  }*/
            /*if (_flag.Equals("last", StringComparison.CurrentCultureIgnoreCase)) {
             *  context.Request
             * }
             * if (_flag.Equals("break", StringComparison.CurrentCultureIgnoreCase)) {
             *
             * }*/
            if (_flag.Equals("redirect", StringComparison.CurrentCultureIgnoreCase))
            {
                context.Response.StatusCode = 302;
                context.Response.Headers.Add("Location", newRequest);
            }
            if (_flag.Equals("permanent", StringComparison.CurrentCultureIgnoreCase))
            {
                context.Response.StatusCode = 301;
                context.Response.Headers.Add("Location", newRequest);
            }
            context.Request.RequestPath = newRequest;
        }
Beispiel #4
0
 public void Execute(HtcHttpContext context)
 {
     if (_type == 1)
     {
         context.ErrorMessageManager.SendError(context, _statusCode);
     }
     else if (_type == 2)
     {
         context.Response.StatusCode = _statusCode;
         context.Response.Headers.Add("Location", HttpIoUtils.ReplaceVars(context, _data));
     }
     else if (_type == 3)
     {
         context.Response.StatusCode = _statusCode;
         context.Response.Write(HttpIoUtils.ReplaceVars(context, _data));
     }
 }
Beispiel #5
0
 public void Execute(HtcHttpContext context)
 {
     foreach (var file in _pages)
     {
         var tempPath = HttpIoUtils.ReplaceVars(context, file);
         if (tempPath[0].Equals('='))
         {
             if (int.TryParse(tempPath.Remove(0, 1), out var statusCode))
             {
                 context.ErrorMessageManager.SendError(context, statusCode);
                 return;
             }
             context.ErrorMessageManager.SendError(context, 500);
             return;
         }
         if (tempPath[0].Equals('@'))
         {
             foreach (var location in _httpLocationManager.Locations)
             {
                 if (!location.Key.Equals(tempPath, StringComparison.CurrentCultureIgnoreCase))
                 {
                     continue;
                 }
                 location.Execute(context);
                 return;
             }
         }
         if (!UrlMapper.RegisteredPages.ContainsKey(tempPath.ToLower()))
         {
             continue;
         }
         if (UrlMapper.RegisteredPages[tempPath.ToLower()].OnHttpPageRequest(context, tempPath.ToLower()))
         {
             context.ErrorMessageManager.SendError(context, 500);
         }
     }
 }