From da8d4ecfae60a807d6c8d884b61699e15378f465 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 30 May 2024 17:29:12 +0100 Subject: [PATCH 1/3] Tweak #8214 by avoiding renaming boot.css Improves the continuity of our GitHub history --- boot/{boot.css => boot.css.tid} | 3 +++ boot/tiddlywiki.files | 7 ++----- 2 files changed, 5 insertions(+), 5 deletions(-) rename boot/{boot.css => boot.css.tid} (96%) diff --git a/boot/boot.css b/boot/boot.css.tid similarity index 96% rename from boot/boot.css rename to boot/boot.css.tid index c0d15f1e3..27c8884cd 100644 --- a/boot/boot.css +++ b/boot/boot.css.tid @@ -1,3 +1,6 @@ +title: $:/boot/boot.css +type: text/css + /* Basic styles used before we boot up the parsing engine */ diff --git a/boot/tiddlywiki.files b/boot/tiddlywiki.files index 38ab5adde..ca4109f09 100644 --- a/boot/tiddlywiki.files +++ b/boot/tiddlywiki.files @@ -25,11 +25,8 @@ } }, { - "file": "boot.css", - "fields": { - "title": "$:/boot/boot.css", - "type": "text/css" - } + "file": "boot.css.tid", + "isTiddlerFile": true } ] } \ No newline at end of file From 65d9384261c639f13299baf8706e529891ffe6bf Mon Sep 17 00:00:00 2001 From: Matt Lauber Date: Thu, 30 May 2024 12:53:22 -0400 Subject: [PATCH 2/3] Add useDefaultHeaders flag to tm-http-request (V2) (#8225) * Add defaultHeaders flag that controls helpful default heders that can sometimes interfere with apis * Bump version number * rename parameter to useDefaultHeaders, and catch one location where the default was not being set properly. * Use a better comparision operator * remove bad change --- core/modules/startup/rootwidget.js | 1 + core/modules/utils/dom/http.js | 13 ++++++++----- .../messages/WidgetMessage_ tm-http-request.tid | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/modules/startup/rootwidget.js b/core/modules/startup/rootwidget.js index 512fc580a..c28bfed66 100644 --- a/core/modules/startup/rootwidget.js +++ b/core/modules/startup/rootwidget.js @@ -39,6 +39,7 @@ exports.startup = function() { method: params.method, body: params.body, binary: params.binary, + useDefaultHeaders: params.useDefaultHeaders, oncompletion: params.oncompletion, onprogress: params.onprogress, bindStatus: params["bind-status"], diff --git a/core/modules/utils/dom/http.js b/core/modules/utils/dom/http.js index ddb1e17c4..9072daaf7 100644 --- a/core/modules/utils/dom/http.js +++ b/core/modules/utils/dom/http.js @@ -69,7 +69,7 @@ HttpClient.prototype.cancelAllHttpRequests = function() { for(var t=this.requests.length - 1; t--; t>=0) { var requestInfo = this.requests[t]; requestInfo.request.cancel(); - } + } } this.requests = []; this.updateRequestTracker(); @@ -112,6 +112,7 @@ function HttpClientRequest(options) { this.method = options.method || "GET"; this.body = options.body || ""; this.binary = options.binary || ""; + this.useDefaultHeaders = options.useDefaultHeaders !== "false" ? true : false, this.variables = options.variables; var url = options.url; $tw.utils.each(options.queryStrings,function(value,name) { @@ -156,6 +157,7 @@ HttpClientRequest.prototype.send = function(callback) { this.xhr = $tw.utils.httpRequest({ url: this.url, type: this.method, + useDefaultHeaders: this.useDefaultHeaders, headers: this.requestHeaders, data: this.body, returnProp: this.binary === "" ? "responseText" : "response", @@ -231,7 +233,8 @@ Make an HTTP request. Options are: exports.httpRequest = function(options) { var type = options.type || "GET", url = options.url, - headers = options.headers || {accept: "application/json"}, + useDefaultHeaders = options.useDefaultHeaders !== false ? true : false, + headers = options.headers || (useDefaultHeaders ? {accept: "application/json"} : {}), hasHeader = function(targetHeader) { targetHeader = targetHeader.toLowerCase(); var result = false; @@ -257,7 +260,7 @@ exports.httpRequest = function(options) { if(hasHeader("Content-Type") && ["application/x-www-form-urlencoded","multipart/form-data","text/plain"].indexOf(getHeader["Content-Type"]) === -1) { return false; } - return true; + return true; }, returnProp = options.returnProp || "responseText", request = new XMLHttpRequest(), @@ -307,10 +310,10 @@ exports.httpRequest = function(options) { request.setRequestHeader(headerTitle,header); }); } - if(data && !hasHeader("Content-Type")) { + if(data && !hasHeader("Content-Type") && useDefaultHeaders) { request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); } - if(!hasHeader("X-Requested-With") && !isSimpleRequest(type,headers)) { + if(!hasHeader("X-Requested-With") && !isSimpleRequest(type,headers) && useDefaultHeaders) { request.setRequestHeader("X-Requested-With","TiddlyWiki"); } // Send data diff --git a/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-http-request.tid b/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-http-request.tid index d2dd6eed7..425da39a8 100644 --- a/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-http-request.tid +++ b/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-http-request.tid @@ -19,6 +19,7 @@ The following parameters are used: |method |HTTP method (eg "GET", "POST") | |body |String data to be sent with the request | |binary |<<.from-version "5.3.1">> Set to "yes" to cause the response body to be treated as binary data and returned in base64 format | +|useDefaultHeaders |<<.from-version "5.3.4">> Defaults to true. Set to "false" to prevent default headers from being added. This can be helpful when dealing with apis that restrict header fields. | |query-* |Query string parameters with string values | |header-* |Headers with string values | |password-header-* |Headers with values taken from the password store | From 7a50b2b554d21fde0a4da03e051c1a0521e71426 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 30 May 2024 17:58:07 +0100 Subject: [PATCH 3/3] Fix tm-copy-to-clipboard crash See https://github.com/Jermolene/TiddlyWiki5/pull/8211#issuecomment-2138600286 --- core/modules/startup/rootwidget.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/modules/startup/rootwidget.js b/core/modules/startup/rootwidget.js index c28bfed66..bfa31362b 100644 --- a/core/modules/startup/rootwidget.js +++ b/core/modules/startup/rootwidget.js @@ -70,8 +70,8 @@ exports.startup = function() { // Install the copy-to-clipboard mechanism $tw.rootWidget.addEventListener("tm-copy-to-clipboard",function(event) { $tw.utils.copyToClipboard(event.param,{ - successNotification: event.paramObject.successNotification, - failureNotification: event.paramObject.failureNotification + successNotification: event.paramObject && event.paramObject.successNotification, + failureNotification: event.paramObject && event.paramObject.failureNotification }); }); // Install the tm-focus-selector message