Enhance Gitea support and ensure UTF-8 encoding in API requests

This commit is contained in:
Matt Batchelder
2026-02-21 19:02:26 -05:00
parent 6c5e503eb2
commit 634e93236f
3 changed files with 35 additions and 6 deletions

View File

@@ -87,17 +87,24 @@ function oribi_sync_api_request( string $method, string $url, array $body, strin
$headers = array_merge(
oribi_sync_auth_headers( $provider, $pat ),
[
'Content-Type' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
'Accept' => 'application/json',
'User-Agent' => 'Oribi-Sync-WP/' . ORIBI_SYNC_VERSION,
]
);
// Ensure UTF-8 encoding of all body content
array_walk_recursive( $body, function ( &$item ) {
if ( is_string( $item ) && ! mb_check_encoding( $item, 'UTF-8' ) ) {
$item = mb_convert_encoding( $item, 'UTF-8' );
}
});
$args = [
'method' => $method,
'timeout' => 30,
'headers' => $headers,
'body' => wp_json_encode( $body ),
'body' => wp_json_encode( $body, JSON_UNESCAPED_UNICODE ),
];
$response = wp_remote_request( $url, $args );