mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Change PAYLOAD input to STDIN (#111)
* change to iron-io/runner dependency * Fix runner dependency * Change PAYLOAD input to STDIN, fixes #40
This commit is contained in:
committed by
Pedro Nasser
parent
b7bf73f5d2
commit
52cab30056
@@ -3,8 +3,8 @@ package server
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/runner/common"
|
||||
"github.com/iron-io/runner/drivers"
|
||||
"github.com/satori/go.uuid"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
func handleSpecial(c *gin.Context) {
|
||||
@@ -45,28 +45,22 @@ func handleRequest(c *gin.Context, enqueue models.Enqueue) {
|
||||
ctx, log = common.LoggerWithFields(ctx, logrus.Fields{"call_id": reqID})
|
||||
|
||||
var err error
|
||||
var payload io.Reader
|
||||
|
||||
var payload []byte
|
||||
if c.Request.Method == "POST" || c.Request.Method == "PUT" {
|
||||
payload, err = ioutil.ReadAll(c.Request.Body)
|
||||
payload = c.Request.Body
|
||||
// Load complete body and close
|
||||
defer func() {
|
||||
io.Copy(ioutil.Discard, c.Request.Body)
|
||||
c.Request.Body.Close()
|
||||
}()
|
||||
} else if c.Request.Method == "GET" {
|
||||
qPL := c.Request.URL.Query()["payload"]
|
||||
if len(qPL) > 0 {
|
||||
payload = []byte(qPL[0])
|
||||
reqPayload := c.Request.URL.Query().Get("payload")
|
||||
if len(reqPayload) > 0 {
|
||||
payload = strings.NewReader(reqPayload)
|
||||
}
|
||||
}
|
||||
|
||||
if len(payload) > 0 {
|
||||
var emptyJSON map[string]interface{}
|
||||
if err := json.Unmarshal(payload, &emptyJSON); err != nil {
|
||||
log.WithError(err).Error(models.ErrInvalidJSON)
|
||||
c.JSON(http.StatusBadRequest, simpleError(models.ErrInvalidJSON))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
log.WithField("payload", string(payload)).Debug("Got payload")
|
||||
|
||||
appName := c.Param("app")
|
||||
if appName == "" {
|
||||
// check context, app can be added via special handlers
|
||||
@@ -115,7 +109,6 @@ func handleRequest(c *gin.Context, enqueue models.Enqueue) {
|
||||
envVars := map[string]string{
|
||||
"METHOD": c.Request.Method,
|
||||
"ROUTE": el.Path,
|
||||
"PAYLOAD": string(payload),
|
||||
"REQUEST_URL": c.Request.URL.String(),
|
||||
}
|
||||
|
||||
@@ -148,6 +141,7 @@ func handleRequest(c *gin.Context, enqueue models.Enqueue) {
|
||||
Stderr: stderr,
|
||||
Env: envVars,
|
||||
Memory: el.Memory,
|
||||
Input: payload,
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
Reference in New Issue
Block a user