peer-at-code-framework/src/dev/peerat/framework/Context.java

35 lines
884 B
Java

package dev.peerat.framework;
public class Context{
private User user;
private int responseCode;
private HttpWriter writer;
private String[] headers;
public Context(User user, HttpWriter writer, String... headers){
this.user = user;
this.writer = writer;
this.headers = headers;
}
public <U extends User> U getUser(){
return (U) user;
}
public void response(int code, String... headers) throws Exception{
if(headers != null && headers.length > 0 && this.headers.length > 0){
String[] copy = new String[this.headers.length+headers.length];
System.arraycopy(this.headers, 0, copy, 0, this.headers.length);
System.arraycopy(headers, 0, copy, this.headers.length, headers.length);
this.headers = copy;
}
this.responseCode = code;
this.writer.response(code, this.headers);
}
public int getResponseCode(){
return this.responseCode;
}
}