Skip to content

Commit 42e2130

Browse files
committed
feat(archive): output status 400 if archive not enabled
1 parent 0172fa9 commit 42e2130

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/serverHandler/archiveTar.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func writeTar(tw *tar.Writer, f *os.File, fInfo os.FileInfo, archivePath string)
4848
}
4949

5050
func (h *handler) tar(w http.ResponseWriter, r *http.Request, pageData *responseData) {
51+
if !pageData.CanArchive {
52+
w.WriteHeader(http.StatusBadRequest)
53+
return
54+
}
55+
5156
selections, ok := h.getArchiveSelections(r)
5257
if !ok {
5358
return
@@ -73,6 +78,11 @@ func (h *handler) tar(w http.ResponseWriter, r *http.Request, pageData *response
7378
}
7479

7580
func (h *handler) tgz(w http.ResponseWriter, r *http.Request, pageData *responseData) {
81+
if !pageData.CanArchive {
82+
w.WriteHeader(http.StatusBadRequest)
83+
return
84+
}
85+
7686
selections, ok := h.getArchiveSelections(r)
7787
if !ok {
7888
return

src/serverHandler/archiveZip.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ func writeZip(zw *zip.Writer, f *os.File, fInfo os.FileInfo, archivePath string)
3838
}
3939

4040
func (h *handler) zip(w http.ResponseWriter, r *http.Request, pageData *responseData) {
41+
if !pageData.CanArchive {
42+
w.WriteHeader(http.StatusBadRequest)
43+
return
44+
}
45+
4146
selections, ok := h.getArchiveSelections(r)
4247
if !ok {
4348
return

src/serverHandler/main.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,16 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
109109
}
110110

111111
// regular flows
112-
113112
if len(r.URL.RawQuery) >= 3 {
114113
switch r.URL.RawQuery[:3] {
115114
case "tar":
116-
if data.CanArchive {
117-
h.tar(w, r, data)
118-
}
115+
h.tar(w, r, data)
119116
return
120117
case "tgz":
121-
if data.CanArchive {
122-
h.tgz(w, r, data)
123-
}
118+
h.tgz(w, r, data)
124119
return
125120
case "zip":
126-
if data.CanArchive {
127-
h.zip(w, r, data)
128-
}
121+
h.zip(w, r, data)
129122
return
130123
}
131124
}

0 commit comments

Comments
 (0)