ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.58k stars 1.33k forks source link

headers are not sent with https:// and :443 #1621

Open sezanzeb opened 3 years ago

sezanzeb commented 3 years ago

The server logs the incoming request headers to verify if they arrived

fails with port on https

function request(url, { method='get', body={} } = {}) {
  url = `https://${config.host}:443${url}`
  return superagent(method, url)
    .set('Authorization', `token ${config.key}:${config.secret}`)
    .send(body)
    .then(res => {
      console.log(res.statusCode)
      return res
    })
    .catch(error => {
      console.log(error.response.statusCode)
      return error.response
    })
}

makes the server not get the authorization header and answer with forbidden

works without port on https

url = `https://${config.host}${url}`

works with port on localhost

http://localhost:8003

works when using the deprecated request package

function request(url, { method='get', body={} } = {}) {
  url = `https://${config.host}:443${url}`
  const options = {
    method,
    url,
    headers: {
      'Authorization': `token ${config.key}:${config.secret}`
    }
  }
  return new Promise((resolve, reject) => {
    Request(options, function (error, response, body) {
      console.log(response.statusCode)
      if (response.statusCode == 200) {
        return resolve(response)
      } else {
        return reject(response)
      }
    })
  })

works with axios

function request(url, { method='get', body={} } = {}) {
  url = `${config.host}:${config.port}${url}`
  return axios({
    method,
    url,
    data: body,
    headers: {
      'Authorization': `token ${config.key}:${config.secret}`
    }
  })
  .then(res => {
    console.log(res.status)
    return res
  })
  .catch(error => {
    console.log(error.response.status)
    return error.response
  })
}

Is there any debugging information I could hand out to you?

version 6.1.0