I run into this error: http: superfluous response.WriteHeader call from main.writeJSONError (server.go:218) When attempting to set the header to StatusInternalServerError AFTER I have already sent the file using http.ServeContent:
`}
w.Header().Set("Content-Disposition", "attachment; filename="+string(keyName))
w.Header().Set("Content-Type", "application/octet-stream")
http.ServeFile(w, r, string(keyName) + ".key") // serve key to user to download
err = diskDelete(keyName) // delete key from disk
if err != nil {
panic(err)
return
}
err = diskDelete(keyName) // delete key from disk again to force error
if err != nil {
writeJSONError(w, "Error in deleteKey", err) // Sets w.WriteHeader to 500
return
}
`
This is annoying because I want to make sure the key is deleted from disk properly before I send the file to user. The obvious problem is that If I delete the file before I send it, then I don't have a file to send. I just learned of the function ServeContent. And maybe there is someway to save the file into a buffer and send that to user. Not exactly sure if that is exactly the function I need though.
I run into this error: http: superfluous response.WriteHeader call from main.writeJSONError (server.go:218) When attempting to set the header to StatusInternalServerError AFTER I have already sent the file using http.ServeContent: `}
`
This is annoying because I want to make sure the key is deleted from disk properly before I send the file to user. The obvious problem is that If I delete the file before I send it, then I don't have a file to send. I just learned of the function ServeContent. And maybe there is someway to save the file into a buffer and send that to user. Not exactly sure if that is exactly the function I need though.