aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Digitigrade/Model/Actor.php15
-rw-r--r--misc/send_request_authenticated.php21
-rw-r--r--routes/actor.php6
3 files changed, 28 insertions, 14 deletions
diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php
index 18aba15..d7fde42 100644
--- a/Digitigrade/Model/Actor.php
+++ b/Digitigrade/Model/Actor.php
@@ -193,12 +193,12 @@ class Actor extends PushableModel implements RpcReceiver {
return;
case 'poke':
- $obj = json_decode($args[1] ?? '');
+ parse_str($args[1], $params);
(new PokeNotif(
$args[0],
- PokeVerb::tryFrom($obj?->verb ?? '') ?? PokeVerb::POKE,
+ PokeVerb::tryFrom($params['verb'] ?? '') ?? PokeVerb::POKE,
$this,
- $obj?->urgent ?? false
+ isset($params['urgent'])
))->processNotifications();
return;
@@ -348,10 +348,11 @@ class Actor extends PushableModel implements RpcReceiver {
}
public function poke(self $target, PokeVerb $verb = PokeVerb::POKE, bool $urgent = false) {
- $target->rpcCall('poke', [$this, json_encode([
- 'verb' => $verb->value,
- 'urgent' => $urgent
- ])], $target->getPokeEndpoint());
+ $params = ['verb' => $verb->value];
+ if ($urgent) {
+ $params['urgent'] = '1';
+ }
+ $target->rpcCall('poke', [$this, http_build_query($params)], $target->getPokeEndpoint());
}
public function isPokeable(): bool {
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);
diff --git a/routes/actor.php b/routes/actor.php
index a459640..7bf0250 100644
--- a/routes/actor.php
+++ b/routes/actor.php
@@ -163,7 +163,7 @@ Router::getInstance()->mount('/actor/:id/poke', function (array $args) {
if ($initiator == null) {
throw new Unauthorized('please authenticate yourself on behalf of the initiating actor');
}
- $body = file_get_contents('php://input');
- $obj = json_decode($body);
- $initiator->poke($target, PokeVerb::tryFrom($obj?->verb ?? '') ?? PokeVerb::POKE, $obj?->urgent ?? false);
+ $verb = PokeVerb::tryFrom($_POST['verb'] ?? '') ?? PokeVerb::POKE;
+ $urgent = isset($_POST['urgent']);
+ $initiator->poke($target, $verb, $urgent);
}); \ No newline at end of file