MCPcopy Index your code
hub / github.com/dagger/dagger / ServeHTTPToNestedClient

Method ServeHTTPToNestedClient

engine/server/session.go:1055–1118  ·  view source on GitHub ↗

ServeHTTPToNestedClient serves nested clients, including module function calls.

(
	w http.ResponseWriter,
	r *http.Request,
	nestedClientMetadata *engine.ClientMetadata,
	callerClientID string,
	hostServiceProxyToCaller bool,
	moduleCtx dagql.AnyObjectResult,
	functionCall dagql.Typed,
	envCtx dagql.AnyObjectResult,
)

Source from the content-addressed store, hash-verified

1053
1054// ServeHTTPToNestedClient serves nested clients, including module function calls.
1055func (srv *Server) ServeHTTPToNestedClient(
1056 w http.ResponseWriter,
1057 r *http.Request,
1058 nestedClientMetadata *engine.ClientMetadata,
1059 callerClientID string,
1060 hostServiceProxyToCaller bool,
1061 moduleCtx dagql.AnyObjectResult,
1062 functionCall dagql.Typed,
1063 envCtx dagql.AnyObjectResult,
1064) {
1065 if nestedClientMetadata == nil {
1066 http.Error(w, "nested client metadata is nil", http.StatusInternalServerError)
1067 return
1068 }
1069 clientMetadata := nestedClientMetadataForRequest(r.Header, nestedClientMetadata)
1070
1071 var moduleContext dagql.ObjectResult[*core.Module]
1072 if moduleCtx != nil {
1073 typed, ok := moduleCtx.(dagql.ObjectResult[*core.Module])
1074 if !ok {
1075 http.Error(w, fmt.Sprintf("nested client module context is %T, not Module", moduleCtx), http.StatusInternalServerError)
1076 return
1077 }
1078 if typed.Self() != nil {
1079 moduleContext = typed
1080 }
1081 }
1082
1083 var fnCall *core.FunctionCall
1084 if functionCall != nil {
1085 typed, ok := functionCall.(*core.FunctionCall)
1086 if !ok {
1087 http.Error(w, fmt.Sprintf("nested client function call is %T, not FunctionCall", functionCall), http.StatusInternalServerError)
1088 return
1089 }
1090 fnCall = typed
1091 }
1092
1093 var envContext dagql.ObjectResult[*core.Env]
1094 if envCtx != nil {
1095 typed, ok := envCtx.(dagql.ObjectResult[*core.Env])
1096 if !ok {
1097 http.Error(w, fmt.Sprintf("nested client env context is %T, not Env", envCtx), http.StatusInternalServerError)
1098 return
1099 }
1100 if typed.Self() != nil {
1101 envContext = typed
1102 }
1103 }
1104
1105 var hostServiceProxyClientID string
1106 if hostServiceProxyToCaller {
1107 hostServiceProxyClientID = callerClientID
1108 }
1109
1110 httpHandlerFunc(srv.serveHTTPToClient, &ClientInitOpts{
1111 ClientMetadata: clientMetadata,
1112 CallerClientID: callerClientID,

Callers

nothing calls this directly

Calls 5

httpHandlerFuncFunction · 0.85
SelfMethod · 0.80
ErrorMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected