MCPcopy
hub / github.com/pocketbase/pocketbase / processInternalRequest

Function processInternalRequest

apis/batch.go:275–388  ·  view source on GitHub ↗
(
	activeApp core.App,
	baseEvent *core.RequestEvent,
	ir *core.InternalRequest,
	infoContext string,
	optNext func(data any) error,
)

Source from the content-addressed store, hash-verified

273}
274
275func processInternalRequest(
276 activeApp core.App,
277 baseEvent *core.RequestEvent,
278 ir *core.InternalRequest,
279 infoContext string,
280 optNext func(data any) error,
281) (*BatchRequestResult, error) {
282 handle, params, ok := prepareInternalAction(activeApp, ir, optNext)
283 if !ok {
284 return nil, errors.New("unknown batch request action")
285 }
286
287 // construct a new http.Request
288 // ---------------------------------------------------------------
289 buf, mw, err := multipartDataFromInternalRequest(ir)
290 if err != nil {
291 return nil, err
292 }
293
294 r, err := http.NewRequest(strings.ToUpper(ir.Method), ir.URL, buf)
295 if err != nil {
296 return nil, err
297 }
298
299 // cleanup multipart temp files
300 defer func() {
301 if r.MultipartForm != nil {
302 if err := r.MultipartForm.RemoveAll(); err != nil {
303 activeApp.Logger().Warn("failed to cleanup temp batch files", "error", err)
304 }
305 }
306 }()
307
308 // load batch request path params
309 // ---
310 for k, v := range params {
311 r.SetPathValue(k, v)
312 }
313
314 // clone original request
315 // ---
316 r.RequestURI = r.URL.RequestURI()
317 r.Proto = baseEvent.Request.Proto
318 r.ProtoMajor = baseEvent.Request.ProtoMajor
319 r.ProtoMinor = baseEvent.Request.ProtoMinor
320 r.Host = baseEvent.Request.Host
321 r.RemoteAddr = baseEvent.Request.RemoteAddr
322 r.TLS = baseEvent.Request.TLS
323
324 if s := baseEvent.Request.TransferEncoding; s != nil {
325 s2 := make([]string, len(s))
326 copy(s2, s)
327 r.TransferEncoding = s2
328 }
329
330 if baseEvent.Request.Trailer != nil {
331 r.Trailer = baseEvent.Request.Trailer.Clone()
332 }

Callers 2

processMethod · 0.85

Calls 11

ParseJSONRawFunction · 0.92
prepareInternalActionFunction · 0.85
copyFunction · 0.85
SetAllMethod · 0.80
LoggerMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
RemoveAllMethod · 0.45
CloneMethod · 0.45
GetAllMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…