From e72af5e2ee3087f94e444f7f8c7cb78610404f40 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 31 Aug 2021 12:13:58 +0300 Subject: [PATCH] examples: fix 404 status code for not found pages in examples/http_server.v --- examples/http_server.v | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/http_server.v b/examples/http_server.v index ffcc299dbf..9d7b04351c 100644 --- a/examples/http_server.v +++ b/examples/http_server.v @@ -10,13 +10,23 @@ fn (h ExampleHandler) handle(req Request) Response { CommonHeader.content_type: 'text/plain' }) } + mut status_code := 200 res.text = match req.url { - '/foo' { 'bar\n' } - '/hello' { 'world\n' } - '/' { 'foo\nhello\n' } - else { 'Not found\n' } + '/foo' { + 'bar\n' + } + '/hello' { + 'world\n' + } + '/' { + 'foo\nhello\n' + } + else { + status_code = 404 + 'Not found\n' + } } - res.status_code = if res.text == 'Not found' { 404 } else { 200 } + res.status_code = status_code return res }