diff options
author | tv <tv@iiso> | 2011-09-15 00:15:36 +0200 |
---|---|---|
committer | tv <tv@iiso> | 2011-09-15 00:15:36 +0200 |
commit | 668ca493744636a5fe090d431f9d36e97be7907b (patch) | |
tree | fd6b37c092494e8c0af4485687fc5f3676307c24 /hyper | |
parent | b172e0b1314d1eaec8f72710e6b44ef3acdd859a (diff) |
//hyper/process: route POST /proc/{id} to stdin
Diffstat (limited to 'hyper')
-rw-r--r-- | hyper/process/main.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/hyper/process/main.go b/hyper/process/main.go index ebeeb6d6..5420f681 100644 --- a/hyper/process/main.go +++ b/hyper/process/main.go @@ -6,6 +6,7 @@ import "http" import "gorilla.googlecode.com/hg/gorilla/mux" import "os" import "fmt" +import "bytes" import "hyper/process" @@ -47,13 +48,29 @@ func RetrieveProcess(res http.ResponseWriter, req *http.Request) { } } +func FeedProcess(res http.ResponseWriter, req *http.Request) { + if p := proc[mux.Vars(req)["id"]]; p != nil { + body := make([]byte, 4096) + if _, err := req.Body.Read(body); err == nil { + body = bytes.TrimRight(body, string([]byte{0})) + p.Write(body) + //if err := p.Write(body); err == nil { + RespondJSON(res, true) + //} + } + } else { + res.WriteHeader(http.StatusNotFound) + } +} + func main() { // Gorilla mux.HandleFunc("/proc", CreateProcessHandler).Methods("POST") mux.HandleFunc("/proc/{id}", RetrieveProcess).Methods("GET") + mux.HandleFunc("/proc/{id}", FeedProcess).Methods("POST") - err := http.ListenAndServe(":8888", mux.DefaultRouter) + err := http.ListenAndServe("0.0.0.0:8888", mux.DefaultRouter) if err != nil { log.Fatal("ListenAndServe: ", err.String()) } |