more efficient caching
This commit is contained in:
@@ -16,6 +16,8 @@ import (
|
||||
|
||||
func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface, cache *expirable.LRU[string, string]) {
|
||||
requestPath := path.Clean(r.URL.Path)
|
||||
requestPath = strings.Trim(requestPath, "/")
|
||||
|
||||
if data, exists := cache.Get(requestPath); exists {
|
||||
w.Header().Set("Content-Type", "text/xml; charset=\"utf-8\"")
|
||||
w.WriteHeader(http.StatusMultiStatus)
|
||||
@@ -26,14 +28,14 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To
|
||||
var output []byte
|
||||
var err error
|
||||
|
||||
filteredSegments := strings.Split(strings.Trim(requestPath, "/"), "/")
|
||||
filteredSegments := strings.Split(requestPath, "/")
|
||||
|
||||
switch len(filteredSegments) {
|
||||
case 0:
|
||||
switch {
|
||||
case len(filteredSegments) == 1 && filteredSegments[0] == "":
|
||||
output, err = handleRoot(w, r, c)
|
||||
case 1:
|
||||
case len(filteredSegments) == 1:
|
||||
output, err = handleListOfTorrents(requestPath, w, r, t, c)
|
||||
case 2:
|
||||
case len(filteredSegments) == 2:
|
||||
output, err = handleSingleTorrent(requestPath, w, r, t)
|
||||
default:
|
||||
writeHTTPError(w, "Not Found", http.StatusNotFound)
|
||||
|
||||
Reference in New Issue
Block a user