add an app server
parent
3d6c613a00
commit
a88957060e
@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func requestsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Printf("we have %d requests in history when user checked", len(requestHistory))
|
||||
for _, req := range requestHistory {
|
||||
fmt.Fprintln(w, req.RequestURI)
|
||||
}
|
||||
}
|
||||
|
||||
func appServer() {
|
||||
var addr string
|
||||
if err := conf.Get("app_addr", &addr); err != nil {
|
||||
bail(1, "error reading app_addr from config: %s", err)
|
||||
}
|
||||
|
||||
m := http.NewServeMux()
|
||||
m.HandleFunc("/requests", requestsHandler)
|
||||
http.ListenAndServe(addr, m)
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var lastId int
|
||||
|
||||
func freezeRequest(r *http.Request) error {
|
||||
var buf bytes.Buffer
|
||||
if _, err := buf.ReadFrom(r.Body); err != nil {
|
||||
return fmt.Errorf("unable to clone request: error reading original request body: %s", err)
|
||||
}
|
||||
|
||||
if err := r.Body.Close(); err != nil {
|
||||
return fmt.Errorf("unable to clone request: cannot close original request body: %s", err)
|
||||
}
|
||||
r.Body = ioutil.NopCloser(&buf)
|
||||
return nil
|
||||
}
|
||||
|
||||
var requestHistory []http.Request
|
@ -1,3 +1,7 @@
|
||||
# address for web browsers to use in their proxy settings. Browsers send their
|
||||
# normal traffic to this port to be proxied.
|
||||
proxy_addr: ":8080"
|
||||
|
||||
# http address for the user app. Users navigate to this address to view their
|
||||
# prox history.
|
||||
app_addr: ":9000"
|
||||
|
Loading…
Reference in New Issue