| 38 | } |
| 39 | |
| 40 | func (mc *ControllerCallClient) Invoke(ir *api.InvokeRequest) (response *api.InvokeResponse, err error) { |
| 41 | h := make(map[string]string, 0) |
| 42 | reqID := id.GetRequestID() |
| 43 | |
| 44 | clientMode := controller.ClientModeHTTPTrigger |
| 45 | ctx := controller.InvokeContext{ |
| 46 | RunOptions: mc.runOptions, |
| 47 | ExternalRequestID: ir.RequestID, |
| 48 | RequestID: reqID, |
| 49 | AccountID: ir.UserID, |
| 50 | Authorization: ir.Authorization, |
| 51 | Clients: mc.controllerClient.NewClients(clientMode), |
| 52 | Response: api.NewInvokeProxyResponseWithRequestID(ir.RequestID), |
| 53 | Logger: logs.NewLogger().WithField("request_id", reqID). |
| 54 | WithField("external_request_id", ir.RequestID), |
| 55 | FunctionBRN: ir.FunctionBRN, |
| 56 | Qualifier: ir.Qualifier, |
| 57 | WithStreamMode: ir.WithBodyStream, |
| 58 | InvokeType: api.InvokeTypeHttpTrigger, |
| 59 | TriggerType: api.TriggerTypeHTTP, |
| 60 | } |
| 61 | |
| 62 | if ir.WithBodyStream { |
| 63 | ctx.Request = api.NewInvokeProxyRequest(h, nil, ir.BodyStream) |
| 64 | } else { |
| 65 | ctx.Request = api.NewInvokeProxyRequest(h, []byte(*ir.Body), nil) |
| 66 | } |
| 67 | |
| 68 | if mc.runOptions.RecommendedOptions.Features.EnableMetrics { |
| 69 | ctx.Metrics = controller.NewInvokeMetrics(ir.RequestID) |
| 70 | } |
| 71 | |
| 72 | mc.controllerClient.Do(&ctx) |
| 73 | |
| 74 | response = api.NewInvokeResponse() |
| 75 | response.SetStatusCode(ctx.Response.StatusCode) |
| 76 | response.SetHeaders(&ctx.Response.Headers) |
| 77 | if ctx.WithStreamMode { |
| 78 | response.SetBodyStream(ctx.Response.BodyStream) |
| 79 | } else { |
| 80 | response.SetBody(ctx.Response.Body) |
| 81 | } |
| 82 | |
| 83 | if ctx.Metrics != nil { |
| 84 | ctx.Metrics.Overall() |
| 85 | ctx.Metrics.WriteSummary(mc.runOptions.RecommendedOptions.Features.SummaryOverheadMs) |
| 86 | } |
| 87 | |
| 88 | return response, nil |
| 89 | } |