post<T> method

Future<XRPCResponse<T>> post<T>(
  1. NSID methodId, {
  2. String? service,
  3. Map<String, String>? headers,
  4. Map<String, dynamic>? parameters,
  5. dynamic body,
  6. ResponseDataBuilder<T>? to,
  7. PostClient? client,
})

Implementation

Future<xrpc.XRPCResponse<T>> post<T>(
  final NSID methodId, {
  final String? service,
  final Map<String, String>? headers,
  final Map<String, dynamic>? parameters,
  final dynamic body,
  final xrpc.ResponseDataBuilder<T>? to,
  final xrpc.PostClient? client,
}) async {
  await _maybeRefreshBeforeSend();
  await _ensureOAuthSessionResolved();
  final resolvedService = service ?? this.service;
  final endpoint = _endpointFor(resolvedService, methodId);

  final callerHeaders = {..._headers ?? const {}, ...headers ?? const {}};
  final callerHasAuth = _hasAuthorization(callerHeaders);

  return await _challenge.execute(
    () async {
      // When the caller already supplied an `Authorization` header (e.g. a
      // service-auth Bearer token for the video service), leave it intact:
      // do not attach the OAuth DPoP `Authorization`/proof that would
      // clobber it.
      final oauthHeaders = callerHasAuth
          ? const <String, String>{}
          : await _oauthAuthHeaders(endpoint, 'POST');
      return await xrpc.procedure(
        methodId,
        protocol: _protocol,
        service: resolvedService,
        headers: {...callerHeaders, ...oauthHeaders},
        parameters: parameters,
        body: body,
        to: to,
        timeout: _timeout,
        // Legacy Bearer path still uses the sync header builder; OAuth
        // headers are already merged above, so only attach the builder
        // when there is no OAuth manager.
        headerBuilder: oAuthSessionManager == null ? _buildAuthHeader : null,
        postClient: client ?? _postClient,
      );
    },
    isProcedure: true,
    nsid: methodId.toString(),
    onUpdateDpopNonce: (h) => _onUpdateDpopNonce(endpoint, h),
    onUnauthorized: _onUnauthorized,
  );
}