BastliBridge

A bot framework bridgin multiple IM protocols, and mail
git clone git://xatko.vsos.ethz.ch/BastliBridge.git
Log | Files | Refs | Submodules

commit dd1c1917232c051c2f8134106ecf55ca45eb220b
parent 0adfd3b82431a1608ccb1bdae4c4484526da6ba6
Author: Dominik Schmidt <das1993@hotmail.com>
Date:   Tue,  3 Oct 2017 21:30:37 +0200

Do some error-handling in http-proxy

Diffstat:
src/proxy.d | 48++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/src/proxy.d b/src/proxy.d @@ -16,7 +16,28 @@ immutable string index=` / __ / /| | \__ \ / / / / / / / /_/ / ___ |___/ // / / /____/ / /_____/_/ |_/____//_/ /_____/___/ -`; +`c; + +immutable string fof=` + _ _ ___ _ _ +| || | / _ \| || | +| || |_| | | | || |_ +|__ _| |_| |__ _| + |_| \___/ |_| +`c; + +immutable string teapot=r" + _ + _,(_)._ + ___,(_______). + ,'__. \ /\_ + /,' / \ / / +| | | |,' / + \`.| / + `. : : / + `. :.,' + `-.________,-' +"c; void bridge(Socket ins, Socket outs, ubyte[] buf){ trace("Bridging between sockets"); @@ -60,9 +81,28 @@ void handleClient(Socket newsock){ not_found(); } else{ - auto path=telegram.getFile(req.url[2..$]); - if(path.length==0){ - not_found(); + string path; + try{ + path=telegram.getFile(req.url[2..$]); + if(path.length==0){ + not_found(); + return; + } + } + catch(TelegramException e){ + res.response(404, "Not Found"); + res.header("Connection", "close"); + res.header("Content-Type", "text/plain"); + res.data(fof); + res.perform(newsock); + return; + } + catch(Exception e){ + res.response(418, "I'm a teapot"); + res.header("Connection", "close"); + res.header("Content-Type", "text/plain"); + res.data(teapot); + res.perform(newsock); return; } static HttpRequest!void r2;