Skip to content

Proxy server sent wrong host header to redirected url #46

Description

@martinpl

Hello,
I have issue with Stremio proxy server. I'm passing link that contains redirection. Redirection go to wanted url but it hits there loop and ends on "maximum redirect reached".
Problem is that streamio pass orginal "host" header to second request and that why there is loop.

My quick fix (end of fetch method)

// HTTP-redirect fetch step 5
if (request.counter >= request.follow) {
    reject(new FetchError(`maximum redirect reached at: ${request.url}`, 'max-redirect'));
    finalize();
    return;
}

// just update host to new location
request.headers.set('host', new URL(locationURL).host)

// HTTP-redirect fetch step 6 (counter increment)
// Create a new Request object.
const requestOpts = {
    headers: new Headers(request.headers),
    follow: request.follow,
    counter: request.counter + 1,
    agent: request.agent,
    compress: request.compress,
    method: request.method,
    body: request.body
};

// HTTP-redirect fetch step 9
if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
    reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
    finalize();
    return;
}

// HTTP-redirect fetch step 11
if (res.statusCode === 303 || (res.statusCode === 301 || res.statusCode === 302) && request.method === 'POST') {
    requestOpts.method = 'GET';
    requestOpts.body = undefined;
    requestOpts.headers.delete('content-length');
}

// HTTP-redirect fetch step 15
resolve(fetch(new Request(locationURL, requestOpts)));
finalize();
return;

PS. Thanks for great app :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions