From 554bbcec2e00df1bf8c03d9fa2d62a4e005c5bfb Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Sat, 19 Jun 2021 12:27:58 -0500 Subject: [PATCH] 404 response respects accepted content type --- server.pl | 5 +++-- static/index.html | 9 ++++++++- test/run.sh | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/server.pl b/server.pl index d3250d5..f512254 100644 --- a/server.pl +++ b/server.pl @@ -441,6 +441,7 @@ EOF my ($cgi, $email) = @_; my $plan = util_get_plan($email); + my $format = $cgi->param('accept')->match(qw(text/plain application/json)); if (defined $plan && defined $plan->{'redirect'}) { # found external plan service, redirect request @@ -448,7 +449,8 @@ EOF return; } if (!defined $plan) { - print_response($cgi, 404); + my $body = $format eq 'text/plain' ? 'No Plan.' : encode_json({error => 'No Plan.'}); + print_response($cgi, 404, {'Content-Type' => $format}, $body); return; } my $pubkey = $cgi->http('X-Dotplan-Pubkey'); @@ -469,7 +471,6 @@ EOF # render response my $body; delete $plan->{'mtime'}; - my $format = $cgi->param('accept')->match(qw(text/plain application/json)); if ($format eq 'application/json') { $body = encode_json($plan); } else { diff --git a/static/index.html b/static/index.html index c9389f7..4c5542d 100644 --- a/static/index.html +++ b/static/index.html @@ -8,7 +8,14 @@

Dotplan Online

-

This site is coming soon. For now you can check out the source code. +

What is Dotplan?

+

Dotplan is a modern re-imagining of the Plan file from the days of yesteryear. Well, I mean technically it's still around today, but when was the last time you fingered someone?

+

On second thought, never mind. Don't answer that...

+

Essentially it's a loosey-goosey API specification through which the technically elite can express their personalities (or lack thereof) with one another.

+

What is Dotplan Online?

+

This site is a free Dotplan provider and relay running the Dotplan reference implementation. If you're some kind of simpleton who is incapable of hosting your own, you can point your email domain here via a SRV record and use it as your Dotplan provider.

+

How does it all work?

+

diff --git a/test/run.sh b/test/run.sh index 2266b0b..73fe81e 100755 --- a/test/run.sh +++ b/test/run.sh @@ -183,7 +183,7 @@ curl_test 'Get authentication token' 200 'application/json' -u $TEST_USER:test12 token=$(echo "$TEST_CONTENT" | jq -r '.token') -curl_test 'No plan by default' 404 'application/json' localhost:$PORT/plan/$TEST_USER +curl_test 'No plan by default' 404 'text/plain' localhost:$PORT/plan/$TEST_USER curl_test 'Reject bad authentication token' 401 'application/json' -XPUT -d '{"plan":"something","auth":"wrong"}' localhost:$PORT/plan/$TEST_USER