From ad84ba3b456f1a9858fcfe1fee28b81197654c8d Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sat, 5 Mar 2022 14:16:40 +0100 Subject: [PATCH] Add separate handling of response status. --- src/jrw/Request.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/jrw/Request.java b/src/jrw/Request.java index abe7161..5065320 100644 --- a/src/jrw/Request.java +++ b/src/jrw/Request.java @@ -5,6 +5,8 @@ import java.util.*; public class Request { public final Map env; public final Map resp = new HashMap<>(); + public String status = "200 OK"; + public Object body = null; public Request(Map env) { this.env = env; @@ -29,7 +31,7 @@ public class Request { } @SuppressWarnings("unchecked") - public void ohead(String name, Object val, boolean repl) { + public Request ohead(String name, Object val, boolean repl) { name = "http." + name; if(repl) { resp.put(name, val); @@ -42,9 +44,15 @@ public class Request { else resp.put(name, new ArrayList(Arrays.asList(cur, val))); } + return(this); } + public Request status(String status) {this.status = status; return(this);} + public Request body(Object body) {this.body = body; return(this);} + public Map response() { + resp.put("http.status", status); + resp.put("jagi.output", body); return(resp); } } -- 2.11.0