diff --git a/components/http.js b/components/http.js index 5be5a46..9bf8483 100644 --- a/components/http.js +++ b/components/http.js @@ -1,3 +1,5 @@ +var URL = require('url'); + var SteamCommunity = require('../index.js'); SteamCommunity.prototype.httpRequest = function(uri, options, callback, source) { @@ -19,6 +21,16 @@ SteamCommunity.prototype.httpRequest = function(uri, options, callback, source) delete this._httpRequestConvenienceMethod; } + // Add origin header if necessary + // https://github.com/DoctorMcKay/node-steamcommunity/issues/351 + if ((options.method || 'GET').toUpperCase() != 'GET') { + options.headers = options.headers || {}; + if (!options.headers.origin) { + var parsedUrl = URL.parse(options.url); + options.headers.origin = parsedUrl.protocol + '//' + parsedUrl.host; + } + } + var requestID = ++this._httpRequestID; source = source || "";