Skip to content

Commit 8e048f7

Browse files
committed
feat(serverHandler): skip indexing sub items for archiving request
1 parent b8b94d6 commit 8e048f7

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/serverHandler/aliasHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ func (h *aliasHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
120120

121121
if data.IsMutate && h.mutate(w, r, session, data) {
122122
return
123-
} else if len(r.URL.RawQuery) >= 3 {
124-
switch r.URL.RawQuery[:3] {
123+
} else if data.IsArchive {
124+
switch data.ArchiveFormat {
125125
case "tar":
126126
if h.tar(w, r, session, data) {
127127
return

src/serverHandler/sessionData.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ type responseData struct {
7676
IsMkdir bool
7777
IsDelete bool
7878
IsMutate bool
79+
IsArchive bool
80+
ArchiveFormat string
7981

8082
CanIndex bool
8183
CanUpload bool
@@ -379,6 +381,23 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
379381
isMutate = true
380382
}
381383

384+
isArchive := false
385+
archiveFormat := ""
386+
if len(rawQuery) == 3 || (len(rawQuery) > 3 && rawQuery[3] == '&') {
387+
rawQuery3 := rawQuery[:3]
388+
switch rawQuery3 {
389+
case "tar":
390+
isArchive = true
391+
archiveFormat = rawQuery3
392+
case "tgz":
393+
isArchive = true
394+
archiveFormat = rawQuery3
395+
case "zip":
396+
isArchive = true
397+
archiveFormat = rawQuery3
398+
}
399+
}
400+
382401
accepts := acceptHeaders.ParseAccepts(r.Header.Get("Accept"))
383402
_, preferredContentType, _ := accepts.GetPreferredValue(acceptContentTypes)
384403
wantJson := preferredContentType == contentTypeJson
@@ -407,8 +426,8 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
407426
}
408427
}
409428

410-
canIndex := authSuccess && h.index.match(vhostReqPath, fsPath, authUserId)
411-
indexFile, indexItem, _statIdxErr := h.statIndexFile(vhostReqPath, fsPath, item, canIndex && redirectAction == noRedirect)
429+
canIndex := authSuccess && redirectAction == noRedirect && h.index.match(vhostReqPath, fsPath, authUserId)
430+
indexFile, indexItem, _statIdxErr := h.statIndexFile(vhostReqPath, fsPath, item, canIndex)
412431
if _statIdxErr != nil {
413432
errs = append(errs, _statIdxErr)
414433
status = getStatusByErr(_statIdxErr)
@@ -435,13 +454,13 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
435454

436455
itemName := getItemName(item, r)
437456

438-
subItems, _readdirErr := readdir(file, item, canIndex && !isMutate && redirectAction == noRedirect && NeedResponseBody(r.Method))
457+
subItems, _readdirErr := readdir(file, item, canIndex && !isMutate && !isArchive && NeedResponseBody(r.Method))
439458
if _readdirErr != nil {
440459
errs = append(errs, _readdirErr)
441460
status = http.StatusInternalServerError
442461
}
443462

444-
subItems, aliasSubItems, _mergeErrs := h.mergeAlias(vhostReqPath, item, subItems, canIndex && redirectAction == noRedirect)
463+
subItems, aliasSubItems, _mergeErrs := h.mergeAlias(vhostReqPath, item, subItems, canIndex)
445464
if len(_mergeErrs) > 0 {
446465
errs = append(errs, _mergeErrs...)
447466
status = http.StatusInternalServerError
@@ -514,6 +533,8 @@ func (h *aliasHandler) getSessionData(r *http.Request) (session *sessionContext,
514533
IsMkdir: isMkdir,
515534
IsDelete: isDelete,
516535
IsMutate: isMutate,
536+
IsArchive: isArchive,
537+
ArchiveFormat: archiveFormat,
517538

518539
CanIndex: canIndex,
519540
CanUpload: canUpload,

0 commit comments

Comments
 (0)