diff --git a/core/modules/server/authenticators/header.js b/core/modules/server/authenticators/header.js index 9d9990d31..cc1d6bdaf 100644 --- a/core/modules/server/authenticators/header.js +++ b/core/modules/server/authenticators/header.js @@ -37,7 +37,9 @@ HeaderAuthenticator.prototype.authenticateRequest = function(request,response,st return false; } else { // authenticatedUsername will be undefined for anonymous users - state.authenticatedUsername = $tw.utils.decodeURIComponentSafe(username); + if(username) { + state.authenticatedUsername = $tw.utils.decodeURIComponentSafe(username); + } return true; } }; diff --git a/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-http-request Examples.tid b/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-http-request Examples.tid new file mode 100644 index 000000000..53ea600ca --- /dev/null +++ b/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-http-request Examples.tid @@ -0,0 +1,117 @@ +created: 20240609152203076 +modified: 20240614210714914 +tags: +title: WidgetMessage: tm-http-request Examples +type: text/vnd.tiddlywiki + +<$let store-fetched-output="""\procedure store-fetched-output() +<$action-setfield $tiddler=Output status=<> error=<> data=<> headers=<>/> +\end +"""> +<$testcase> +<$data title=Description text="Simple tm-http-request GET"/> +<$data title=Narrative text="""Use the oncompletion attribute to store the results of a method="GET" request"""/> +<$data title=Output text=`$(store-fetched-output)$ +\procedure http-get() + <$action-sendmessage + $message="tm-http-request" + url="https://httpbin.org/get" + method="GET" + oncompletion=<> + /> +\end + +<$button actions=<>>send HTTP GET`/> + + +<$testcase> +<$data title=Description text="Simple tm-http-request POST"/> +<$data title=Narrative text="""Use the oncompletion attribute to store the results of a method="POST" request. Use the body attribute to send data"""/> +<$data title=Output text=`$(store-fetched-output)$ +\procedure http-post() + <$action-sendmessage + $message="tm-http-request" + url="https://httpbin.org/post" + method="POST" + body='{"foo": "bar"}' + oncompletion=<> + /> +\end + +<$button actions=<>>send HTTP POST`/> + + +<$testcase> +<$data title=Description text="tm-http-request with delayed response"/> +<$data title=Narrative text="""Use the bind-status and bind-progress attributes to watch the intermediate state of a slow response"""/> +<$data title=Output text=`$(store-fetched-output)$ +\procedure http-get() + <$action-sendmessage + $message="tm-http-request" + url="https://httpbin.org/delay/2" + bind-status=status + bind-progress=progress + method="GET" + oncompletion=<> + /> +\end + +<$button actions=<>>send HTTP GET + +|!status |{{status}}| +|!progress %|{{progress}}|`/> + + +<$testcase> +<$data title=Description text="tm-http-request with dripped response"/> +<$data title=Narrative text="""Use the bind-status and bind-progress attributes to watch progress of data which arrives a little at a time"""/> +<$data title=Output text=`$(store-fetched-output)$ +\procedure http-get() + <$action-sendmessage + $message="tm-http-request" + url="https://httpbin.org/drip?duration=2&numbytes=10&code=200&delay=2" + bind-status=status + bind-progress=progress + method="GET" + oncompletion=<> + /> +\end + +<$button actions=<>>send HTTP GET + +|!status |{{status}}| +|!progress %|{{progress}}|`/> + + +<$testcase> +<$data title=Description text="tm-http-request 504 Bad Gateway error response"/> +<$data title=Narrative text="""Send a request to a url which simulates a 504 HTTP response in order to illustrate what an error response looks like"""/> +<$data title=Output text=`$(store-fetched-output)$ +\procedure http-get() + <$action-sendmessage + $message="tm-http-request" + url="https://httpbin.org/status/504" + method="GET" + oncompletion=<> + /> +\end + +<$button actions=<>>send HTTP GET`/> + + +<$testcase> +<$data title=Description text="tm-http-request 405 Method Not Allowed error response"/> +<$data title=Narrative text="""Another error response example. This one sends a GET to a URL which only allows POST"""/> +<$data title=Output text=`$(store-fetched-output)$ +\procedure http-get() + <$action-sendmessage + $message="tm-http-request" + url="https://httpbin.org/post" + method="GET" + oncompletion=<> + /> +\end + +<$button actions=<>>send HTTP GET`/> + + 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 9006fc7cd..d6efcb27c 100644 --- a/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-http-request.tid +++ b/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-http-request.tid @@ -1,6 +1,6 @@ caption: tm-http-request created: 20230429161453032 -modified: 20230723215344887 +modified: 20240614204704401 tags: Messages title: WidgetMessage: tm-http-request type: text/vnd.tiddlywiki @@ -54,6 +54,7 @@ Note that the state tiddler $:/state/http-requests contains a number representin !! Examples +* Several simple examples using https://httpbin.org: [[WidgetMessage: tm-http-request Examples]] * [[Zotero's|https://www.zotero.org/]] API for retrieving reference items: [[WidgetMessage: tm-http-request Example - Zotero]] * [[Random Dog's|https://random.dog/]] API for retrieving random pictures of dogs showing how to retrieve binary data: [[WidgetMessage: tm-http-request Example - Random Dog]] * Example of using HTTP Basic Authentication: [[WidgetMessage: tm-http-request Example - Basic Authentication]]