Skip to content

Commit

Permalink
Fixed handling of absolute and relative paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Apr 10, 2024
1 parent e9ac2e8 commit cdd4a74
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ func main() {

path := filepath.Base(r.PathValue("path"))
log.Println("processing " + path)
reqpath := filepath.Join(staging, path)

if !strings.HasPrefix(path, "request-") {
dumpErrorResponse(w, http.StatusBadRequest, "file name should start with \"request-\"", path)
return
}
reqtype := strings.TrimPrefix(path, "request-")

reqpath := filepath.Join(staging, path)
info, err := os.Stat(reqpath)
if err != nil {
dumpErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to stat; %v", err), reqpath)
dumpErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to stat; %v", err), path)
return
}
if info.IsDir() {
dumpErrorResponse(w, http.StatusBadRequest, "path is a directory", reqpath)
return
}

if !strings.HasPrefix(reqpath, "request-") {
dumpErrorResponse(w, http.StatusBadRequest, "file name should start with \"request-\"", reqpath)
dumpErrorResponse(w, http.StatusBadRequest, "path is a directory", path)
return
}
reqtype := strings.TrimPrefix(reqpath, "request-")

var reportable_err error
payload := map[string]interface{}{}
Expand Down Expand Up @@ -136,14 +136,14 @@ func main() {

if reportable_err == nil {
payload["status"] = "SUCCESS"
dumpJsonResponse(w, http.StatusOK, &payload, reqpath)
dumpJsonResponse(w, http.StatusOK, &payload, path)
} else {
status_code := http.StatusInternalServerError
var http_err *httpError
if errors.As(reportable_err, &http_err) {
status_code = http_err.Status
}
dumpErrorResponse(w, status_code, reportable_err.Error(), reqpath)
dumpErrorResponse(w, status_code, reportable_err.Error(), path)
}
})

Expand Down

0 comments on commit cdd4a74

Please sign in to comment.