@@ -154,7 +154,7 @@ func exitHandler(w http.ResponseWriter, r *http.Request) {
154
154
155
155
func hostnameHandler (w http.ResponseWriter , r * http.Request ) {
156
156
log .Printf ("GET /hostname" )
157
- fmt .Fprintf (w , getHostName ())
157
+ fmt .Fprint (w , getHostName ())
158
158
}
159
159
160
160
// healthHandler response with a 200 if the UDP server is ready. It also serves
@@ -247,7 +247,7 @@ func dialHandler(w http.ResponseWriter, r *http.Request) {
247
247
}
248
248
bytes , err := json .Marshal (output )
249
249
if err == nil {
250
- fmt .Fprintf (w , string (bytes ))
250
+ fmt .Fprint (w , string (bytes ))
251
251
} else {
252
252
http .Error (w , fmt .Sprintf ("response could not be serialized. %v" , err ), http .StatusExpectationFailed )
253
253
}
@@ -314,7 +314,7 @@ func shellHandler(w http.ResponseWriter, r *http.Request) {
314
314
log .Printf ("Output: %s" , output )
315
315
bytes , err := json .Marshal (output )
316
316
if err == nil {
317
- fmt .Fprintf (w , string (bytes ))
317
+ fmt .Fprint (w , string (bytes ))
318
318
} else {
319
319
http .Error (w , fmt .Sprintf ("response could not be serialized. %v" , err ), http .StatusExpectationFailed )
320
320
}
@@ -328,7 +328,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
328
328
result ["error" ] = "Unable to upload file."
329
329
bytes , err := json .Marshal (result )
330
330
if err == nil {
331
- fmt .Fprintf (w , string (bytes ))
331
+ fmt .Fprint (w , string (bytes ))
332
332
} else {
333
333
http .Error (w , fmt .Sprintf ("%s. Also unable to serialize output. %v" , result ["error" ], err ), http .StatusInternalServerError )
334
334
}
@@ -342,7 +342,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
342
342
result ["error" ] = "Unable to open file for write"
343
343
bytes , err := json .Marshal (result )
344
344
if err == nil {
345
- fmt .Fprintf (w , string (bytes ))
345
+ fmt .Fprint (w , string (bytes ))
346
346
} else {
347
347
http .Error (w , fmt .Sprintf ("%s. Also unable to serialize output. %v" , result ["error" ], err ), http .StatusInternalServerError )
348
348
}
@@ -354,7 +354,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
354
354
result ["error" ] = "Unable to write file."
355
355
bytes , err := json .Marshal (result )
356
356
if err == nil {
357
- fmt .Fprintf (w , string (bytes ))
357
+ fmt .Fprint (w , string (bytes ))
358
358
} else {
359
359
http .Error (w , fmt .Sprintf ("%s. Also unable to serialize output. %v" , result ["error" ], err ), http .StatusInternalServerError )
360
360
}
@@ -367,7 +367,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
367
367
result ["error" ] = "Unable to chmod file."
368
368
bytes , err := json .Marshal (result )
369
369
if err == nil {
370
- fmt .Fprintf (w , string (bytes ))
370
+ fmt .Fprint (w , string (bytes ))
371
371
} else {
372
372
http .Error (w , fmt .Sprintf ("%s. Also unable to serialize output. %v" , result ["error" ], err ), http .StatusInternalServerError )
373
373
}
@@ -378,12 +378,16 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
378
378
result ["output" ] = UploadFile
379
379
w .WriteHeader (http .StatusCreated )
380
380
bytes , err := json .Marshal (result )
381
- fmt .Fprintf (w , string (bytes ))
381
+ if err != nil {
382
+ http .Error (w , fmt .Sprintf ("%s. Also unable to serialize output. %v" , result ["error" ], err ), http .StatusInternalServerError )
383
+ return
384
+ }
385
+ fmt .Fprint (w , string (bytes ))
382
386
}
383
387
384
388
func hostNameHandler (w http.ResponseWriter , r * http.Request ) {
385
389
log .Printf ("GET /hostName" )
386
- fmt .Fprintf (w , getHostName ())
390
+ fmt .Fprint (w , getHostName ())
387
391
}
388
392
389
393
// udp server supports the hostName, echo and clientIP commands.
0 commit comments