-
-
Save carlosmn/b7002ad50a34626d6870df3b76745ecf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Perform snapshot of domain console | |
func DomainVNCSnapshot(w http.ResponseWriter, r *http.Request) { | |
ruuid := chi.URLParam(r, "uuid") | |
errstr := "Failure retrieving VM details" | |
domobj, err := GetDomObj(ruuid) | |
if err != nil { | |
http.Error(w, errstr, http.StatusInternalServerError) | |
return | |
} | |
defer domobj.Free() | |
// A screenshot is streamed so set up a non-blocking stream to receive it | |
st, err := conn.NewStream(1) | |
if err != nil { | |
http.Error(w, "Error setting up image stream", http.StatusInternalServerError) | |
return | |
} | |
defer st.Free() | |
mime, err := domobj.Screenshot(st, 0, 0) | |
if err != nil { | |
http.Error(w, "Error taking screenshot", http.StatusInternalServerError) | |
return | |
} | |
// We took the screenshot so we can tell the client everything went well | |
// and what kind of image they can expect. | |
w.Header().Set("Content-Type", mime) | |
w.WriteHeader(http.SatusOk) | |
// Copy the screenshot data into the client's stream | |
st.RecvAll(func(st *Stream, data []byte) (int, error) { | |
return w.Write(data) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment