@@ -0,0 +1,2825 @@
+package com.wizzardo.http;%0A%0Aimport com.wizzardo.http.request.Request;%0Aimport com.wizzardo.http.response.Response;%0Aimport com.wizzardo.http.response.Status;%0A%0Aimport java.io.IOException;%0Aimport java.nio.charset.StandardCharsets;%0A%0A/**%0A * Created by wizzardo on 16.04.15.%0A */%0Apublic class RestHandler implements Handler %7B%0A%0A    protected Handler get;%0A    protected Handler post;%0A    protected Handler put;%0A    protected Handler delete;%0A%0A    private byte%5B%5D allow;%0A%0A    @Override%0A    public Response handle(Request request, Response response) throws IOException %7B%0A        switch (request.method()) %7B%0A            case GET:%0A                return handle(request, response, get);%0A            case PUT:%0A                return handle(request, response, put);%0A            case POST:%0A                return handle(request, response, post);%0A            case DELETE:%0A                return handle(request, response, delete);%0A        %7D%0A        return response.setStatus(Status._405);%0A    %7D%0A%0A    protected Response handle(Request request, Response response, Handler handler) throws IOException %7B%0A        if (handler == null)%0A            return provideAllowHeader(response).setStatus(Status._405);%0A        else%0A            return handler.handle(request, response);%0A    %7D%0A%0A    protected Response provideAllowHeader(Response response) %7B%0A        if (allow != null)%0A            response.appendHeader(allow);%0A        return response;%0A    %7D%0A%0A    public RestHandler setGetHandler(Handler get) %7B%0A        this.get = get;%0A        generateAllowHeader();%0A        return this;%0A    %7D%0A%0A    public RestHandler setPostHandler(Handler post) %7B%0A        this.post = post;%0A        generateAllowHeader();%0A        return this;%0A    %7D%0A%0A    public RestHandler setPutHandler(Handler put) %7B%0A        this.put = put;%0A        generateAllowHeader();%0A        return this;%0A    %7D%0A%0A    public RestHandler setDeleteHandler(Handler delete) %7B%0A        this.delete = delete;%0A        generateAllowHeader();%0A        return this;%0A    %7D%0A%0A    private void generateAllowHeader() %7B%0A        StringBuilder sb = new StringBuilder(%22Allow: %22);%0A        boolean comma;%0A%0A        comma = buildAllowHeaderString(sb, get, %22GET%22, false);%0A        comma = buildAllowHeaderString(sb, post, %22POST%22, comma);%0A        comma = buildAllowHeaderString(sb, put, %22PUT%22, comma);%0A        comma = buildAllowHeaderString(sb, delete, %22DELETE%22, comma);%0A%0A        if (sb.length() %3E 7)%0A            allow = sb.append(%22%5Cr%5Cn%22).toString().getBytes(StandardCharsets.UTF_8);%0A        else%0A            allow = null;%0A    %7D%0A%0A    private boolean buildAllowHeaderString(StringBuilder sb, Handler handler, String name, boolean comma) %7B%0A        if (handler != null) %7B%0A            if (comma)%0A                sb.append(%22, %22);%0A            else%0A                comma = true;%0A            sb.append(name);%0A        %7D%0A        return comma;%0A    %7D%0A%7D%0A

add RestHandler