MCPcopy Create free account
hub / github.com/danderson/netboot / handleFile

Method handleFile

pixiecore/http.go:121–162  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

119}
120
121func (s *Server) handleFile(w http.ResponseWriter, r *http.Request) {
122 name := r.URL.Query().Get("name")
123 if name == "" {
124 s.debug("HTTP", "Bad request %q from %s, missing filename", r.URL, r.RemoteAddr)
125 http.Error(w, "missing filename", http.StatusBadRequest)
126 }
127
128 f, sz, err := s.Booter.ReadBootFile(ID(name))
129 if err != nil {
130 s.log("HTTP", "Error getting file %q (query %q from %s): %s", name, r.URL, r.RemoteAddr, err)
131 http.Error(w, "couldn't get file", http.StatusInternalServerError)
132 return
133 }
134 defer f.Close()
135 if sz >= 0 {
136 w.Header().Set("Content-Length", strconv.FormatInt(sz, 10))
137 } else {
138 s.log("HTTP", "Unknown file size for %q, boot will be VERY slow (can your Booter provide file sizes?)", name)
139 }
140 if _, err = io.Copy(w, f); err != nil {
141 s.log("HTTP", "Copy of %q to %s (query %q) failed: %s", name, r.RemoteAddr, r.URL, err)
142 return
143 }
144 s.log("HTTP", "Sent file %q to %s", name, r.RemoteAddr)
145
146 switch r.URL.Query().Get("type") {
147 case "kernel":
148 mac, err := net.ParseMAC(r.URL.Query().Get("mac"))
149 if err != nil {
150 s.log("HTTP", "File fetch provided invalid MAC address %q", r.URL.Query().Get("mac"))
151 return
152 }
153 s.machineEvent(mac, machineStateKernel, "Sent kernel %q", name)
154 case "initrd":
155 mac, err := net.ParseMAC(r.URL.Query().Get("mac"))
156 if err != nil {
157 s.log("HTTP", "File fetch provided invalid MAC address %q", r.URL.Query().Get("mac"))
158 return
159 }
160 s.machineEvent(mac, machineStateInitrd, "Sent initrd %q", name)
161 }
162}
163
164func (s *Server) handleBooting(w http.ResponseWriter, r *http.Request) {
165 // Return a no-op boot script, to satisfy iPXE. It won't get used,

Callers 1

TestFileFunction · 0.95

Calls 7

debugMethod · 0.95
logMethod · 0.95
machineEventMethod · 0.95
IDTypeAlias · 0.85
CopyMethod · 0.80
ReadBootFileMethod · 0.65
CloseMethod · 0.45

Tested by 1

TestFileFunction · 0.76