MCPcopy
hub / github.com/openfaas/faas / MakeQueuedProxy

Function MakeQueuedProxy

gateway/handlers/queue_proxy.go:25–68  ·  view source on GitHub ↗

MakeQueuedProxy accepts work onto a queue

(metrics metrics.MetricOptions, queuer ftypes.RequestQueuer, pathTransformer middleware.URLPathTransformer, defaultNS string, functionQuery scaling.FunctionQuery)

Source from the content-addressed store, hash-verified

23
24// MakeQueuedProxy accepts work onto a queue
25func MakeQueuedProxy(metrics metrics.MetricOptions, queuer ftypes.RequestQueuer, pathTransformer middleware.URLPathTransformer, defaultNS string, functionQuery scaling.FunctionQuery) http.HandlerFunc {
26 return func(w http.ResponseWriter, r *http.Request) {
27 var body []byte
28 if r.Body != nil {
29 defer r.Body.Close()
30
31 var err error
32 body, err = io.ReadAll(r.Body)
33 if err != nil {
34 http.Error(w, err.Error(), http.StatusBadRequest)
35 return
36 }
37 }
38
39 callbackURL, err := getCallbackURLHeader(r.Header)
40 if err != nil {
41 http.Error(w, err.Error(), http.StatusBadRequest)
42 return
43 }
44
45 vars := mux.Vars(r)
46 name := vars["name"]
47
48 req := &ftypes.QueueRequest{
49 Function: name,
50 Body: body,
51 Method: r.Method,
52 QueryString: r.URL.RawQuery,
53 Path: pathTransformer.Transform(r),
54 Header: r.Header,
55 Host: r.Host,
56 CallbackURL: callbackURL,
57 }
58
59 if err = queuer.Queue(req); err != nil {
60 log.Printf("Error queuing request: %v", err)
61 http.Error(w, fmt.Sprintf("Error queuing request: %s", err.Error()),
62 http.StatusInternalServerError)
63 return
64 }
65
66 w.WriteHeader(http.StatusAccepted)
67 }
68}
69
70func getCallbackURLHeader(header http.Header) (*url.URL, error) {
71 value := header.Get("X-Callback-Url")

Callers 1

mainFunction · 0.92

Calls 2

getCallbackURLHeaderFunction · 0.85
TransformMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…