|
@@ -4,6 +4,7 @@ import (
|
|
|
"io"
|
|
|
"log"
|
|
|
"net/http"
|
|
|
+ "strings"
|
|
|
"sync"
|
|
|
)
|
|
|
|
|
@@ -54,17 +55,25 @@ func pathHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ if h := r.Header.Get("Connection"); len(h) > 0 && strings.ToLower(h) == "upgrade" {
|
|
|
+ if h = r.Header.Get("Upgrade"); len(h) > 0 && strings.ToLower(h) == "websocket" {
|
|
|
+ info("Websocket connections not supported yet. Headers: %+v", r.Header)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if r.Method == "GET" {
|
|
|
- log.Printf("%s [GET] Connected", pathID)
|
|
|
+ info("%s [GET] Connected", pathID)
|
|
|
handleGet(pathID, w, r)
|
|
|
- } else {
|
|
|
- log.Printf("%s [POST] Connected", pathID)
|
|
|
+ } else if r.Method == "POST" {
|
|
|
+ info("%s [POST] Connected", pathID)
|
|
|
if h := r.Header.Get("X-Pathway"); h == "pubsub" {
|
|
|
debug("%s [PUBSUB] Upgrade POST to PUBSUB", pathID)
|
|
|
handlePubSub(pathID, r)
|
|
|
} else {
|
|
|
handlePost(pathID, r)
|
|
|
}
|
|
|
+ } else {
|
|
|
+ info("Unhandled request type: '%s'", r.Method)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -78,7 +87,7 @@ func emptyHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
- log.Printf("pathway version:%s buildtime:%s", version, buildtime)
|
|
|
+ info("pathway version:%s buildtime:%s", version, buildtime)
|
|
|
|
|
|
http.HandleFunc("/health", okHandler)
|
|
|
http.HandleFunc("/favicon.ico", emptyHandler)
|
|
@@ -87,12 +96,16 @@ func main() {
|
|
|
|
|
|
err := http.ListenAndServe(":8080", nil)
|
|
|
if err != nil {
|
|
|
- log.Println(err)
|
|
|
+ info("%s", err.Error())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func info(msg string, args ...interface{}) {
|
|
|
+ log.Printf("INFO | "+msg, args...)
|
|
|
+}
|
|
|
+
|
|
|
func debug(msg string, args ...interface{}) {
|
|
|
if len(debugging) > 0 {
|
|
|
- log.Printf(msg, args...)
|
|
|
+ log.Printf("DEBUG | "+msg, args...)
|
|
|
}
|
|
|
}
|