Skip to content

Commit

Permalink
feat: add vendor http header to cached responses (RSS-Bridge#4040)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan authored Mar 31, 2024
1 parent 8ca1b90 commit 7328932
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion actions/DisplayAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function execute(Request $request)
return new Response('', 304, ['last-modified' => $modificationTimeGMT . 'GMT']);
}
}
return $cachedResponse;
return $cachedResponse->withHeader('rss-bridge', 'This is a cached response');
}

if (!$bridgeName) {
Expand Down
7 changes: 6 additions & 1 deletion bridges/MediapartBlogsBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public function collectData()

$item['title'] = $item_title->innertext;
$item['uri'] = self::BASE_URI . trim($item_title->href);
$item['author'] = $element->find('.author .subscriber', 0)->innertext;

$author = $element->find('.author .subscriber', 0);
if ($author) {
$item['author'] = $author->innertext;
}

$item['content'] = $item_divs[count($item_divs) - 2] . $item_divs[count($item_divs) - 1];
$item['timestamp'] = strtotime($element->find('.author time', 0)->datetime);

Expand Down
2 changes: 0 additions & 2 deletions lib/FeedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ public function setAuthor($author)
} else {
$this->author = $author;
}
return $this;
}

public function getContent(): ?string
Expand Down Expand Up @@ -284,7 +283,6 @@ public function addMisc($name, $value)
} else {
$this->misc[$name] = $value;
}
return $this;
}

public function toArray(): array
Expand Down
9 changes: 8 additions & 1 deletion lib/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,14 @@ public function getHeader(string $name, bool $all = false)
return array_pop($header);
}

public function withBody(string $body): Response
public function withHeader(string $name, string $value): self
{
$clone = clone $this;
$clone->headers[$name] = [$value];
return $clone;
}

public function withBody(string $body): self
{
$clone = clone $this;
$clone->body = $body;
Expand Down

0 comments on commit 7328932

Please sign in to comment.