Add origin header to all non-GET requests

This commit is contained in:
Alex Corn 2025-02-12 03:04:45 -05:00
parent 1c1ff82543
commit ac222ef8c3
No known key found for this signature in database
GPG Key ID: 4E25AE41FE0072C7

View File

@ -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 || "";