diff --git a/src/dev/peerat/framework/Context.java b/src/dev/peerat/framework/Context.java index 5ca3aaa..9a0142b 100644 --- a/src/dev/peerat/framework/Context.java +++ b/src/dev/peerat/framework/Context.java @@ -34,11 +34,15 @@ public class Context{ } 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; + if(headers != null && headers.length > 0){ + if(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; + }else{ + this.headers = headers; + } } this.responseCode = code; this.writer.response(code, this.headers); diff --git a/src/dev/peerat/framework/HttpReader.java b/src/dev/peerat/framework/HttpReader.java index edf44b3..e0e11a5 100644 --- a/src/dev/peerat/framework/HttpReader.java +++ b/src/dev/peerat/framework/HttpReader.java @@ -41,7 +41,7 @@ public class HttpReader{ return this.socket.isClosed(); } - public void readHeaders() throws Exception{ + void readHeaders() throws Exception{ String line; while(((line = reader.readLine()) != null) && (line.length() > 0)){ Matcher matcher = HEADER_PATTERN.matcher(line);