package com.hamishrickerby.http_server;

/**
 * Created by rickerbh on 29/08/2016.
 */
public class FourEightTeenResponse extends Response {
    public FourEightTeenResponse(Request request) {
        super(request);
    }

    @Override
    protected int code() {
        if (isRequestCoffee()) {
            return 418;
        }
        return super.code();
    }

    @Override
    protected String reason() {
        if (isRequestCoffee()) {
            return "I'm a teapot";
        }
        return super.reason();
    }

    protected byte[] body() {
        if (isRequestCoffee()) {
            String bodyContent = "I'm a teapot, short and stout.";
            return bodyContent.getBytes();
        }
        return new byte[0];
    }

    private Boolean isRequestCoffee() {
        return request.getPath().equals("/coffee");
    }

    private Boolean isRequestTea() {
        return request.getPath().equals("/tea");
    }

    public static Boolean existsFor(Request request) {
        FourEightTeenResponse response = new FourEightTeenResponse(request);
        return response.isRequestCoffee() || response.isRequestTea();
    }
}

@@ -134,16 +134,101 @@
 ponse %7B%0A
+    private int code = 200;%0A    private String reason;%0A    private String bodyText;%0A%0A
     publ
@@ -299,56 +299,8 @@
 t);%0A
-    %7D%0A%0A    @Override%0A    protected int code() %7B%0A
     
@@ -340,22 +340,22 @@
         
-return
+code =
  418;%0A  
@@ -364,157 +364,186 @@
     
-%7D%0A
     
-    return super.code()
+reason = %22I'm a teapot%22
 ;%0A    
-%7D%0A%0A
     
-@Override%0A    protected String reason() %7B%0A        if (isRequestCoffee()) %7B%0A            return %22I'm a teapot
+    bodyText = %22I'm a teapot, short and stout.%22;%0A        %7D else %7B%0A            code = 200;%0A            reason = %22OK%22;%0A            bodyText = %22
 %22;%0A 
@@ -559,41 +559,24 @@
     
+%7D%0A%0A
     
-return super.reason();%0A    %7D%0A
+@Override
 %0A   
@@ -590,19 +590,16 @@
 ted 
-byte%5B%5D body
+int code
 () %7B
@@ -611,179 +611,168 @@
     
-if (isRequestCoffee()) %7B
+return code;
 %0A    
+%7D%0A%0A
     
-    String bodyContent = %22I'm a teapot, short and stout.%22;%0A   
+@Override%0A    protected String reason() %7B%0A        return reason;%0A
     
+%7D%0A%0A
     
- return bodyContent.getBytes();%0A        %7D%0A        return new byte%5B0%5D
+protected byte%5B%5D body() %7B%0A        return bodyText.getBytes()
 ;%0A  

Simplify 418 response