put static method

Future<PodResponse> put(
  1. String url,
  2. String content, {
  3. PodContentType contentType = PodContentType.json,
})

Perform a PUT request to create or replace a resource.

Implementation

static Future<PodResponse> put(
  String url,
  String content, {
  PodContentType contentType = PodContentType.json,
}) async {
  try {
    final tokens = await PodAuth.getTokens(url, 'PUT');
    final bodyBytes = utf8.encode(content);

    final response = await http.put(
      Uri.parse(url),
      headers: {
        'Accept': '*/*',
        'Authorization': 'DPoP ${tokens.accessToken}',
        'Connection': 'keep-alive',
        'Content-Type': contentType.value,
        'Content-Length': bodyBytes.length.toString(),
        'DPoP': tokens.dPopToken,
      },
      body: bodyBytes,
    );

    return PodResponse(
      statusCode: response.statusCode,
      body: response.body,
      headers: response.headers,
    );
  } catch (e) {
    debugPrint('PodHttp.put() error: $e');
    rethrow;
  }
}