Add an undocumented option to turn off https

Obviously as this is a monumentally bad idea 99% of the time, don't document it or expose it in the GUI
This commit is contained in:
UnknownShadow200 2020-12-23 23:56:16 +11:00
parent 13dcf51f9f
commit 45fb1d56ab
2 changed files with 12 additions and 2 deletions

View File

@ -6,8 +6,9 @@
#include "Stream.h" #include "Stream.h"
#include "Game.h" #include "Game.h"
#include "Utils.h" #include "Utils.h"
#include "Options.h"
static cc_bool httpsOnly; static cc_bool httpsOnly, httpOnly;
/* Frees data from a HTTP request. */ /* Frees data from a HTTP request. */
static void HttpRequest_Free(struct HttpRequest* request) { static void HttpRequest_Free(struct HttpRequest* request) {
Mem_Free(request->data); Mem_Free(request->data);
@ -119,7 +120,8 @@ static void Http_WorkerStop(void);
/* Adds a req to the list of pending requests, waking up worker thread if needed. */ /* Adds a req to the list of pending requests, waking up worker thread if needed. */
static int Http_Add(const cc_string* url, cc_bool priority, cc_uint8 type, const cc_string* lastModified, static int Http_Add(const cc_string* url, cc_bool priority, cc_uint8 type, const cc_string* lastModified,
const cc_string* etag, const void* data, cc_uint32 size, struct StringsBuffer* cookies) { const cc_string* etag, const void* data, cc_uint32 size, struct StringsBuffer* cookies) {
static const cc_string http = String_FromConst("http://"); static const cc_string https = String_FromConst("https://");
static const cc_string http = String_FromConst("http://");
struct HttpRequest req = { 0 }; struct HttpRequest req = { 0 };
String_CopyToRawArray(req.url, url); String_CopyToRawArray(req.url, url);
@ -133,6 +135,11 @@ static int Http_Add(const cc_string* url, cc_bool priority, cc_uint8 type, const
cc_string url_ = String_FromRawArray(req.url); cc_string url_ = String_FromRawArray(req.url);
if (String_CaselessStarts(&url_, &http)) String_InsertAt(&url_, 4, 's'); if (String_CaselessStarts(&url_, &http)) String_InsertAt(&url_, 4, 's');
} }
/* Change https:// to http:// if required */
if (httpOnly) {
cc_string url_ = String_FromRawArray(req.url);
if (String_CaselessStarts(&url_, &https)) String_DeleteAt(&url_, 4);
}
if (lastModified) { if (lastModified) {
String_CopyToRawArray(req.lastModified, lastModified); String_CopyToRawArray(req.lastModified, lastModified);
@ -1141,6 +1148,8 @@ void Http_UrlEncodeUtf8(cc_string* dst, const cc_string* src) {
*#########################################################################################################################*/ *#########################################################################################################################*/
static void OnInit(void) { static void OnInit(void) {
http_terminate = false; http_terminate = false;
httpOnly = Options_GetBool(OPT_HTTP_ONLY, false);
Http_WorkerInit(); Http_WorkerInit();
ScheduledTask_Add(30, Http_CleanCacheTask); ScheduledTask_Add(30, Http_CleanCacheTask);
RequestList_Init(&pendingReqs); RequestList_Init(&pendingReqs);

View File

@ -70,6 +70,7 @@
#define OPT_GRAB_CURSOR "win-grab-cursor" #define OPT_GRAB_CURSOR "win-grab-cursor"
#define OPT_TOUCH_BUTTONS "gui-touchbuttons" #define OPT_TOUCH_BUTTONS "gui-touchbuttons"
#define OPT_TOUCH_SCALE "gui-touchscale" #define OPT_TOUCH_SCALE "gui-touchscale"
#define OPT_HTTP_ONLY "http-no-https"
struct StringsBuffer; struct StringsBuffer;
extern struct StringsBuffer Options; extern struct StringsBuffer Options;