Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong extracted data when fetching image link behind redirect #524

Open
asdfzdfj opened this issue Sep 16, 2023 · 0 comments
Open

wrong extracted data when fetching image link behind redirect #524

asdfzdfj opened this issue Sep 16, 2023 · 0 comments

Comments

@asdfzdfj
Copy link

when fetching an image link that's behind redirect, the extracted embed info contains no usable info or html for embedding.

the crawler seems to be following redirects fine, but the extracted data wan't updated to reflect the new contents at the redirected location.

not sure if this also apply to other embed resource links.

rough setup/test script

# nginx test server configuration
server {
        listen 10.110.37.5:8888;
        server_name localhost;

        location ~ ^/301/(.*)$ {
                return 301 /$1;
        }

        location ~ ^/302/(.*)$ {
                return 302 /$1;
        }

        location / {
                # put an image named 'hug.jpeg' in here
                root /var/www/redir;
        }
}
<?php

declare(strict_types=1);

require_once('vendor/autoload.php');

use Embed\Embed;
use Symfony\Component\VarDumper\VarDumper;

$ef = new Embed();

$site = 'http://10.110.37.5:8888';
$image = '/hug.jpeg';

$direct = $ef->get($site.$image);
$r301 = $ef->get($site.'/301'.$image);
$r302 = $ef->get($site.'/302'.$image);

dump([
    'direct' => [
        'fetch' => (string) $direct->getRequest()->getUri(),
        'exist' => (bool) $direct,
        'url' => (string) $direct->url,
        'code' => $direct->code
    ],
    '301' => [
        'fetch' => (string) $r301->getRequest()->getUri(),
        'exist' => (bool) $r301,
        'url' => (string) $r301->url,
        'code' => $r301->code
    ],
    '302' => [
        'fetch' => (string) $r302->getRequest()->getUri(),
        'exist' => (bool) $r302,
        'url' => (string) $r302->url,
        'code' => $r302->code
    ],
]);

% php embedtest.php
^ array:3 [
  "direct" => array:4 [
    "fetch" => "http://10.110.37.5:8888/hug.jpeg"
    "exist" => true
    "url" => "http://10.110.37.5:8888/hug.jpeg"
    "code" => Embed\EmbedCode^ {#112
      +html: "<img src="http://10.110.37.5:8888/hug.jpeg" />"
      +width: null
      +height: null
      +ratio: null
    }
  ]
  301 => array:4 [
    "fetch" => "http://10.110.37.5:8888/301/hug.jpeg"
    "exist" => true
    "url" => "http://10.110.37.5:8888/hug.jpeg"
    "code" => null
  ]
  302 => array:4 [
    "fetch" => "http://10.110.37.5:8888/302/hug.jpeg"
    "exist" => true
    "url" => "http://10.110.37.5:8888/hug.jpeg"
    "code" => null
  ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant