فهرست منبع

Fixed http redirection bug

tobychui 2 سال پیش
والد
کامیت
f02503f6a6
3فایلهای تغییر یافته به همراه14 افزوده شده و 4 حذف شده
  1. 4 1
      mod/agi/agi.go
  2. 6 1
      mod/agi/agi.http.go
  3. 4 2
      mod/www/www.go

+ 4 - 1
mod/agi/agi.go

@@ -367,7 +367,10 @@ func (g *Gateway) ExecuteAGIScriptAsUser(fsh *filesystem.FileSystemHandler, scri
 
 				return
 			} else {
-				panic(caught)
+				//Something screwed. Return Internal Server Error
+				w.WriteHeader(http.StatusInternalServerError)
+				w.Write([]byte("500 - ECMA VM crashed due to unknown reason"))
+				//panic(caught)
 			}
 		}
 	}()

+ 6 - 1
mod/agi/agi.http.go

@@ -277,7 +277,12 @@ func (g *Gateway) injectHTTPFunctions(vm *otto.Otto, u *user.User, scriptFsh *fi
 		http.download = _http_download;
 		http.getb64 = _http_getb64;
 		http.getCode = _http_code;
-		http.redirect = _http_redirect;
+		http.redirect = function(t, c){
+			if (typeof(c) == "undefined"){
+				c = 307;
+			}
+			_http_redirect(t,c);
+		};
 	`)
 
 }

+ 4 - 2
mod/www/www.go

@@ -129,8 +129,10 @@ func (h *Handler) RouteRequest(w http.ResponseWriter, r *http.Request) {
 	}
 
 	if filepath.Ext(targetFilePath) == "" {
-		//Reading a folder. Check if index.htm or index.html exists.
-		if fsh.FileSystemAbstraction.FileExists(filepath.Join(targetFilePath, "index.html")) {
+		//Reading a folder. Check if index.agi, index.htm or index.html exists.
+		if fsh.FileSystemAbstraction.FileExists(filepath.Join(targetFilePath, "index.agi")) {
+			targetFilePath = filepath.ToSlash(filepath.Join(targetFilePath, "index.agi"))
+		} else if fsh.FileSystemAbstraction.FileExists(filepath.Join(targetFilePath, "index.html")) {
 			targetFilePath = filepath.ToSlash(filepath.Join(targetFilePath, "index.html"))
 		} else if fsh.FileSystemAbstraction.FileExists(filepath.Join(targetFilePath, "index.htm")) {
 			targetFilePath = filepath.ToSlash(filepath.Join(targetFilePath, "index.htm"))