From a0c5f0e1fb3c3e579637f78e7c218ce6cb0c2db5 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 13 Sep 2020 21:08:24 -0700 Subject: Use parse_headers for media endpoint uploads micropub_media_post_for_user makes a case-sensitive search for the Location header, which fails if the location header is all lowercase. This change uses the `headers` fields, introduced in 2b98a4548e82f1133bf62918b0106ab99a21fa29a, to find the Location header, regardless of case. --- lib/helpers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/helpers.php b/lib/helpers.php index 48ada12..ec23afa 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -120,8 +120,8 @@ function micropub_media_post_for_user(&$user, $file) { $r = micropub_post($user->micropub_media_endpoint, [], $user->micropub_access_token, $file, true, 'file'); // Check the response and look for a "Location" header containing the URL - if($r['response'] && preg_match('/Location: (.+)/', $r['response'], $match)) { - $r['location'] = trim($match[1]); + if($r['headers'] && $r['headers']['Location']) { + $r['location'] = $r['headers']['Location']; } else { $r['location'] = false; } -- cgit v1.2.3