Skip to content

Instantly share code, notes, and snippets.

@tcrowe
Created September 20, 2019 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcrowe/baf35de0048c0985a914219cd6f66569 to your computer and use it in GitHub Desktop.
Save tcrowe/baf35de0048c0985a914219cd6f66569 to your computer and use it in GitHub Desktop.
Testing IONOS cloud, parsing headers, cURL, node
# This approach works. ✅
# The idea is possibly cURL is tolerant to invalid headers.
# How to test:
# 1. Install cURL https://curl.haxx.se/
# 2. In your terminal copy and paste:
curl -v -H 'X-TOKEN: 1234' 'https://cloudpanel-api.ionos.com/v1/servers'
/*
This does not work because nodejs cannot parse the headers. 🐛
How to reproduce:
1. Install nodejs https://nodejs.org/de/
https://nodejs.org/en/
2a. Try to you use your company's module with node: https://github.com/1and1/oneandone-cloudserver-sdk-nodejs
2b. `npm install superagent` and run this script with node
*/
const superagent = require("superagent");
const endpointUrl = "https://cloudpanel-api.ionos.com/v1";
const token = "1234";
superagent
.get("https://cloudpanel-api.ionos.com/v1/servers")
.set("X-TOKEN", token)
.type("json")
.accept("json")
.then(res => console.log("res", res))
.catch(err => console.error("err", err)); // ⬅️⚠️ it will not parse headers
@tcrowe
Copy link
Author

tcrowe commented Jan 17, 2020

In the end we discovered that it was node v12 that would not handle these headers. The solution was downgrade to v10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment