Skip to content

Commit f8f427c

Browse files
committed
ignition: Use http.ServeContent
This does not matter much in the context of ignition, but `http.ServeContent` is more featureful than using `io.Copy`: https://pkg.go.dev/net/http#ServeContent > The main benefit of ServeContent over io.Copy is that it handles Range > requests properly, sets the MIME type, and handles If-Match, > If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests. Signed-off-by: Christophe Fergeau <[email protected]>
1 parent 7ce69df commit f8f427c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

cmd/vfkit/main.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,10 @@ func startIgnitionProvisionerServer(vm *vf.VirtualMachine, configPath string, vs
296296
return startIgnitionProvisionerServerInternal(ignitionReader, listener)
297297
}
298298

299-
func startIgnitionProvisionerServerInternal(ignitionReader io.Reader, listener net.Listener) error {
299+
func startIgnitionProvisionerServerInternal(ignitionReader io.ReadSeeker, listener net.Listener) error {
300300
mux := http.NewServeMux()
301-
mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
302-
_, err := io.Copy(w, ignitionReader)
303-
if err != nil {
304-
log.Errorf("failed to serve ignition file: %v", err)
305-
}
301+
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
302+
http.ServeContent(w, req, "", time.Time{}, ignitionReader)
306303
})
307304

308305
srv := &http.Server{

0 commit comments

Comments
 (0)