Browse Source

add option to send specific accept header

pull/119/head
Aaron Parecki 1 year ago
parent
commit
438430ffc2
3 changed files with 16 additions and 2 deletions
  1. +1
    -0
      README.md
  2. +2
    -1
      controllers/Parse.php
  3. +13
    -1
      lib/XRay/Fetcher.php

+ 1
- 0
README.md View File

@ -66,6 +66,7 @@ In both cases, you can add an additional parameter to configure various options
* `include_original` - Will also return the full document fetched * `include_original` - Will also return the full document fetched
* `target` - Specify a target URL, and XRay will first check if that URL is on the page, and only if it is, will continue to parse the page. This is useful when you're using XRay to verify an incoming webmention. * `target` - Specify a target URL, and XRay will first check if that URL is on the page, and only if it is, will continue to parse the page. This is useful when you're using XRay to verify an incoming webmention.
* `expect=feed` - If you know the thing you are parsing is a feed, include this parameter which will avoid running the autodetection rules and will provide better results for some feeds. * `expect=feed` - If you know the thing you are parsing is a feed, include this parameter which will avoid running the autodetection rules and will provide better results for some feeds.
* `accept` - (options: `html`, `json`, `activitypub`, `xml`) - Without this parameter, XRay sends a default `Accept` header to prioritize getting the most likely best result from a page. If you are parsing a page for a specific purpose and expect to find only one type of content (e.g. webmentions will probably only be from HTML pages), you can include this parameter to adjust the `Accept` header XRay sends.
Additional parameters are supported when making requests that use the Twitter or GitHub API. See the Authentication section below for details. Additional parameters are supported when making requests that use the Twitter or GitHub API. See the Authentication section below for details.

+ 2
- 1
controllers/Parse.php View File

@ -96,7 +96,8 @@ class Parse {
$fields = [ $fields = [
'twitter_api_key','twitter_api_secret','twitter_access_token','twitter_access_token_secret', 'twitter_api_key','twitter_api_secret','twitter_access_token','twitter_access_token_secret',
'github_access_token', 'github_access_token',
'token'
'token',
'accept',
]; ];
foreach($fields as $f) { foreach($fields as $f) {
if($v=$request->get($f)) if($v=$request->get($f))

+ 13
- 1
lib/XRay/Fetcher.php View File

@ -66,7 +66,19 @@ class Fetcher {
$headers = []; $headers = [];
$headers[] = 'Accept: application/mf2+json, application/activity+json, text/html, application/json, application/xml, text/xml';
$accept = 'application/mf2+json, application/activity+json, text/html, application/json, application/xml, text/xml';
if(isset($opts['accept'])) {
if($opts['accept'] == 'html')
$accept = 'text/html';
if($opts['accept'] == 'json')
$accept = 'application/mf2+json, application/activity+json, application/json';
if($opts['accept'] == 'activitypub')
$accept = 'application/activity+json';
if($opts['accept'] == 'xml')
$accept = 'application/xml, text/xml';
}
$headers[] = 'Accept: '.$accept;
if(isset($opts['token'])) if(isset($opts['token']))
$headers[] = 'Authorization: Bearer ' . $opts['token']; $headers[] = 'Authorization: Bearer ' . $opts['token'];

Loading…
Cancel
Save