Skip to content

wrong extracted data when fetching image link behind redirect #524

Open
@asdfzdfj

Description

@asdfzdfj

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
  ]
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions