Skip to content

Commit a0d4196

Browse files
committed
t
1 parent 97de8bf commit a0d4196

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

legacyServer.go

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import (
1919
// Tries to serve a legacy file if available
2020
func ServeLegacy(w http.ResponseWriter, r *http.Request) {
2121

22+
relPath := filepath.ToSlash(path.Join(r.URL.Host, r.URL.Path))
2223
// @TODO PERFORM REQUEST MODIFICATION HERE
24+
// parseHtaccessPath(serverSettings.LegacyHTDOCSPath, filepath.Dir(relPath), w, r)
2325

24-
relPath := filepath.ToSlash(path.Join(r.URL.Host, r.URL.Path))
2526
relPathWithQuery := filepath.ToSlash(path.Join(r.URL.Host, r.URL.Path+url.PathEscape("?"+r.URL.RawQuery)))
2627
hasQuery := r.URL.RawQuery != ""
2728

@@ -274,3 +275,48 @@ func isScriptUrl(u *url.URL) bool {
274275
}
275276
return false
276277
}
278+
279+
// func parseHtaccessPath(root string, relPath string, w http.ResponseWriter, r *http.Request) error {
280+
// // Go from top to bottom
281+
// fmt.Printf("[Legacy] Parsing htaccess files for path: %s\n", relPath)
282+
// nextDir := relPath
283+
// for {
284+
// if nextDir == "" {
285+
// return nil
286+
// }
287+
// // Find .htaccess file in next directory
288+
// htaccessPath := path.Join(root, nextDir, ".htaccess")
289+
// fmt.Printf("[Legacy] Looking for htaccess file: %s\n", htaccessPath)
290+
// file, err := os.Open(htaccessPath)
291+
// if err != nil && os.IsNotExist(err) {
292+
// return err
293+
// } else {
294+
// fmt.Printf("[Legacy] Found htaccess file: %s\n", htaccessPath)
295+
// contents, err := io.ReadAll(file)
296+
// if err != nil {
297+
// return err
298+
// }
299+
// ast, err := parser.Parse(string(contents))
300+
301+
// for _, directive := range ast.Dirs {
302+
// switch directive.Name {
303+
// case "RewriteRule":
304+
// // Expect a split of 3
305+
// if len(directive.Params) != 3 {
306+
// return fmt.Errorf("Invalid RewriteRule directive?")
307+
// }
308+
// src := directive.Params[0]
309+
// dest := directive.Params[1]
310+
// flags := directive.Params[2]
311+
// fmt.Printf("[Legacy] RewriteRule: %s -> %s [%s]\n", src.RawString, dest.RawString, flags.RawString)
312+
// src.Capture([]string{path.Join(r.URL.Host, r.URL.Path)})
313+
// fmt.Printf("[Legacy] var: %s\n", src.VariableName)
314+
// fmt.Printf("[Legacy] ass: %s\n", src.AssignValue)
315+
// default:
316+
// }
317+
// }
318+
319+
// }
320+
// nextDir = filepath.Dir(nextDir)
321+
// }
322+
// }

legacyServer_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,46 @@ func TestServeLegacy200Script(t *testing.T) {
294294
}
295295
}
296296

297+
func TestServeLegacy200Htaccess(t *testing.T) {
298+
htaccessData := []byte(`RewriteEngine On
299+
RewriteRule ^game$ /redirect [R=301,L]`)
300+
htaccessFile := path.Join(testServerSettings.LegacyHTDOCSPath, "example.com", ".htaccess")
301+
// Make directory path
302+
err := os.MkdirAll(path.Dir(htaccessFile), os.ModePerm)
303+
if err != nil {
304+
t.Error(err)
305+
}
306+
err = os.WriteFile(htaccessFile, htaccessData, os.ModePerm)
307+
if err != nil {
308+
t.Error(err)
309+
}
310+
311+
testData := []byte("success")
312+
testFile := path.Join(testServerSettings.LegacyHTDOCSPath, "example.com", "redirect")
313+
// Make directory path
314+
err = os.MkdirAll(path.Dir(testFile), os.ModePerm)
315+
if err != nil {
316+
t.Error(err)
317+
}
318+
err = os.WriteFile(testFile, testData, os.ModePerm)
319+
if err != nil {
320+
t.Error(err)
321+
}
322+
323+
test := &legacyServerTest{
324+
request: makeNewRequest("GET", "http://example.com/game", nil),
325+
response: &legacyServerTestResponse{
326+
statusCode: http.StatusOK,
327+
body: testData,
328+
},
329+
}
330+
331+
err = test.run()
332+
if err != nil {
333+
t.Error(err)
334+
}
335+
}
336+
297337
func TestServeLegacy200ScriptPost(t *testing.T) {
298338
setup(&testServerSettings)
299339

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ type ServerSettings struct {
3737
ExtIndexTypes []string `json:"extIndexTypes"`
3838
ExtMimeTypes map[string]string `json:"extMimeTypes"`
3939
ExtGzippeddTypes []string `json:"extGzippedTypes"`
40-
UseMad4FP bool `json:"useMad4FP"`
4140
HandleLegacyRequests bool `json:"handleLegacyRequests"`
4241
ExternalLegacyPort string `json:"externalLegacyPort"`
4342
LegacyHTDOCSPath string `json:"legacyHTDOCSPath"`
@@ -48,6 +47,7 @@ type ServerSettings struct {
4847
LegacyOverridePaths []string `json:"legacyOverridePaths"`
4948
UseInfinityServer bool `json:"useInfinityServer"`
5049
InfinityServerURL string `json:"infinityServerURL"`
50+
UseMad4FP bool `json:"useMad4FP"`
5151
EnableHttpsProxy bool `json:"enableHttpsProxy"`
5252
}
5353

zipfs

Submodule zipfs updated 1 file

0 commit comments

Comments
 (0)