From eed1646a32c05519aa4779a65bc796eba9adb8bb Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Sun, 10 Sep 2023 17:47:20 +0200 Subject: [PATCH] Fix headers -> was only takes local headers if having global headers --- src/dev/peerat/framework/Context.java | 14 +++++++++----- src/dev/peerat/framework/HttpReader.java | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) 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);