Skip to content

Commit

Permalink
Clean up, only do stuff once
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsager committed Apr 28, 2024
1 parent adaa68b commit 24dd489
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,6 @@ func main() {
w.Header().Add("Server", description)
}

if responseBodyFlag != "" && strings.HasPrefix(responseBodyFlag, "@") {
filename := trimFirst(responseBodyFlag)
s, err := os.Stat(filename)
if err != nil {
log.Printf("error: unable to stat file: '%s'", filename)
return
}
if w.Header().Get("Content-Length") == "" {
w.Header().Add("Content-Length", strconv.Itoa(int(s.Size())))
}
}

if responseBodyFlag != "" {
if strings.HasPrefix(responseBodyFlag, "@") {
// response is filename
Expand Down Expand Up @@ -149,6 +137,8 @@ func main() {
log.Printf("error: unable to write response body: %s", err)
}
}
} else {
w.WriteHeader(int(statusCodeFlag))
}

if exitAfterFlag != 0 && exitAfterFlag == responseCount {
Expand Down

0 comments on commit 24dd489

Please sign in to comment.