index/src/Http/ContentHandling/BencodeContentHandler.php

26 lines
727 B
PHP

<?php
// BencodeContentHandler.php
// Created: 2024-03-28
// Updated: 2024-10-02
namespace Index\Http\ContentHandling;
use Index\Bencode\IBencodeSerializable;
use Index\Http\HttpResponseBuilder;
use Index\Http\Content\BencodedContent;
/**
* Represents a Bencode content handler for building HTTP response messages.
*/
class BencodeContentHandler implements IContentHandler {
public function match(mixed $content): bool {
return $content instanceof IBencodeSerializable;
}
public function handle(HttpResponseBuilder $response, mixed $content): void {
if(!$response->hasContentType())
$response->setTypePlain();
$response->setContent(new BencodedContent($content));
}
}