From 668ca493744636a5fe090d431f9d36e97be7907b Mon Sep 17 00:00:00 2001
From: tv <tv@iiso>
Date: Thu, 15 Sep 2011 00:15:36 +0200
Subject: //hyper/process: route POST /proc/{id} to stdin

---
 hyper/process/main.go | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

(limited to 'hyper')

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())
   }
-- 
cgit v1.2.3