Dirty hack for parsing request
This commit is contained in:
parent
8dab1ce8a9
commit
53163e6f8d
12
node/api.go
12
node/api.go
@ -143,7 +143,13 @@ func (es ESConf) UPointHandler(w http.ResponseWriter, r *http.Request) {
|
||||
LogRequest(r)
|
||||
|
||||
// Log request
|
||||
content, _ := ioutil.ReadAll(r.Body)
|
||||
content, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Error("Fail to parse POST body: ", err.Error())
|
||||
w.WriteHeader(500)
|
||||
w.Write([]byte(fmt.Sprintf("error: %s", err.Error())))
|
||||
return
|
||||
}
|
||||
log.Debugf("Point request is: ", string(content))
|
||||
|
||||
// Get plain POST variables
|
||||
@ -152,6 +158,10 @@ func (es ESConf) UPointHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
pauth := r.Form.Get("pauth")
|
||||
tmsg := r.Form.Get("tmsg")
|
||||
if pauth == "" && tmsg == "" {
|
||||
log.Debug("Trying parse body request")
|
||||
pauth, tmsg = parsePointBody(string(content))
|
||||
}
|
||||
|
||||
req.Pauth = pauth
|
||||
req.Tmsg = tmsg
|
||||
|
@ -1,11 +1,13 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
mrand "math/rand"
|
||||
|
||||
"strings"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
@ -28,3 +30,25 @@ func genAuthString() []byte {
|
||||
|
||||
return authString
|
||||
}
|
||||
|
||||
// parsePointBody without regexp
|
||||
// it dirty hack mades because *http.Request.Form not parsed it
|
||||
func parsePointBody(content string) (string, string) {
|
||||
var pauth, tmsg string
|
||||
log.Debug("Body parser: ", content)
|
||||
if strings.Contains(content, "&") {
|
||||
log.Debug("Found &")
|
||||
for _, v := range strings.Split(content, "&") {
|
||||
if strings.Contains(v, "pauth") {
|
||||
log.Debug("Found pauth")
|
||||
pauth = strings.Split(v, "pauth=")[1]
|
||||
}
|
||||
if strings.Contains(v, "tmsg") {
|
||||
log.Debug("Found tmsg")
|
||||
tmsg = strings.Split(v, "tmsg=")[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pauth, tmsg
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user