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

Doesn't work with usefixie and quotaguard with invalidProxyResponse #650

Open
MihaelIsaev opened this issue Dec 6, 2022 · 3 comments
Open

Comments

@MihaelIsaev
Copy link
Contributor

I tried to use it with usefixie.com and quotaguard.com and getting invalidProxyResponse error.

I tried to set breakpoints to debug the issue and see that under the hood these services returns 400 Bad Request

let auth = HTTPClient.Authorization.basic(username: "fixie", password: "___")
let proxyConfig = HTTPClient.Configuration.Proxy.server(host: "___.usefixie.com", port: 80, authorization: auth)
app.http.client.configuration.proxy = proxyConfig
//app.http.client.configuration.redirectConfiguration = .follow(max: 100, allowCycles: true)
do {
    let res = try app.client.get(URI("https://ip.quotaguard.com/")).wait()
    app.logger.critical("\(res.body?.string)")
} catch {
    app.logger.critical("Error: \(error)") // getting HTTPClientError.invalidProxyResponse here
}

at the same time with nodejs everything works fine

var http = require('http');

function buildAuthHeader(user, pass) {
    return 'Basic ' + new Buffer(user + ':' + pass).toString('base64');
}

proxy = '___.usefixie.com';
proxy_port = 80;
host = 'ip.quotaguard.com';
url = 'https://ip.quotaguard.com';
user = 'fixie';
pass = '___';

var options = {
    port: proxy_port,
    host: proxy,
    path: url,
    headers: {
        Host: host,
        'Proxy-Authorization': buildAuthHeader(user, pass),
    }
};

http.get(options, function(res) {
  console.log("StatusCode: " + res.statusCode + " Message: " + res.statusMessage);
  let chunks = []
    res.on('data', chunk => chunks.push(chunk))
    res.on('end', () => {
      console.log('DONE', Buffer.concat(chunks).toString('utf8'))
    })
}).end();
@Lukasa
Copy link
Collaborator

Lukasa commented Dec 6, 2022

Can you use Wireshark or something similar to capture the request to the proxy and then provide it here?

MihaelIsaev added a commit to MihaelIsaev/async-http-client that referenced this issue Dec 6, 2022
@MihaelIsaev
Copy link
Contributor Author

@Lukasa thanks for pointing me to Wireshark, I completely forgot about it!

I realized that Host header is missing which causes 400 Bad Request: missing required Host header

I added missing header into HTTP1ProxyConnectionHandler and now it works like a charm!

Lukasa pushed a commit that referenced this issue Dec 6, 2022
@MihaelIsaev
Copy link
Contributor Author

@Lukasa thank you very much for merging it that fast! Need it in production asap, could you please tag it?

MihaelIsaev added a commit to MihaelIsaev/async-http-client that referenced this issue Dec 6, 2022
MihaelIsaev added a commit to MihaelIsaev/async-http-client that referenced this issue Dec 6, 2022
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

2 participants