zjael / simple-proxy-agent

Simple agent for sending HTTP and HTTPS traffic through HTTP and SOCKS proxies
MIT License
25 stars 5 forks source link

Mysterious 421 Misdirected Request Error #24

Open restyler opened 4 years ago

restyler commented 4 years ago

I'm getting weird 421 error and I think it's related to simple proxy agent since after switching agent to https://github.com/TooTallNate/node-proxy-agent exact same code works fine.

image

Only certain webservers produce this error (github is one of them), I guess it has something to do with HTTP2 and/or SNI.

I've tried to debug it via tcpdump but I don't see any major differences between two agents in protocol..

Steps to reproduce:


const fetch = require('node-fetch')
const ProxyAgent = require('simple-proxy-agent')

const TSProxyAgent = require('https-proxy-agent');

url = 'https://raw.githubusercontent.com/imakewebthings/waypoints/master/licenses.txt'

addrProxy2 = "http://any-proxy-http-or-socks"

let agent = ProxyAgent(addrProxy2)

console.log ('421 redirect err')
fetch(url, {agent})
.then(async (resp) => {
    console.log(resp)
})
.catch(err => {
    console.error(err)
})
.finally(() => {

    let agent2 = TSProxyAgent(addrProxy2)

    console.log('200 OK with tootallnate agent:')
    fetch(url, {agent: agent2})
    .then(async (resp) => {
        console.log(resp)
    })
    .catch(err => {
        console.error(err)
    })

})
zjael commented 4 years ago

Thank you for reporting, i can't quite spot the problem yet. Gonna have to dig a bit deeper. 😄