aboutsummaryrefslogtreecommitdiffhomepage
path: root/misc/send_request_authenticated.php
diff options
context:
space:
mode:
authorwinter2025-03-24 19:19:11 +0000
committerwinter2025-03-24 19:19:11 +0000
commit0a83d6a3f27b90355d450ce6b8390303c169a47f (patch)
tree33a520b6a064c62dd86a047c02a61211938c094e /misc/send_request_authenticated.php
parent6d06ec92a35b8d38c24f246944d40431e8ec6f4f (diff)
[breaking] change poke extension to use form-urlencoded instead of json
https://pawpub.entities.org.uk/extension/poke?do=diff&rev2%5B0%5D=1742657519&rev2%5B1%5D=1742841374&difftype=sidebyside
Diffstat (limited to 'misc/send_request_authenticated.php')
-rw-r--r--misc/send_request_authenticated.php21
1 files changed, 17 insertions, 4 deletions
diff --git a/misc/send_request_authenticated.php b/misc/send_request_authenticated.php
index 6e74cac..842334c 100644
--- a/misc/send_request_authenticated.php
+++ b/misc/send_request_authenticated.php
@@ -17,7 +17,8 @@ function send_request_authenticated(
bool $dontLookUpInstance = false,
string $method = 'GET',
?Actor $actingAs = null,
- ?string $body = null
+ ?string $body = null,
+ ?string $contentType = null
) {
if (!str_starts_with($uri, 'https://')) {
throw new RuntimeException('refusing to fetch a non-https uri');
@@ -33,10 +34,18 @@ function send_request_authenticated(
$instance = Instance::findByHostname($remoteHost);
}
+ if ($body != null && $method != 'GET') {
+ $contentType ??= 'application/x-www-form-urlencoded';
+ }
+
if (!isset($instance->auth->outboundToken) || $instance->auth->outboundToken == null) {
// hopefully we can make the request anyway?
- $context = stream_context_create(['http' => ['method' => $method, 'content' => $body]]);
- $resp = file_get_contents($uri);
+ $context = stream_context_create(['http' => [
+ 'method' => $method,
+ 'content' => $body,
+ 'header' => isset($contentType) ? "Content-Type: $contentType" : null
+ ]]);
+ $resp = file_get_contents($uri, context: $context);
// $http_response_header just poofs into existence .
// i don't like this api. i should probably use curl instead. hmm
// TODO: use curl instead of file_get_contents
@@ -56,9 +65,13 @@ function send_request_authenticated(
if ($actingAs != null) {
$header .= "\nX-PawPub-Actor: $actingAs->uri";
}
+ if ($contentType != null) {
+ $header .= "\nContent-Type: $contentType";
+ }
$context = stream_context_create(['http' => [
'method' => $method,
- 'header' => $header
+ 'header' => $header,
+ 'content' => $body
]]);
$result = new stdClass();
$result->body = file_get_contents($uri, context: $context);