diff --git a/core/src/main/java/spotty/common/http/HttpHeaders.java b/core/src/main/java/spotty/common/http/HttpHeaders.java
index 9371d97..b42bef6 100644
--- a/core/src/main/java/spotty/common/http/HttpHeaders.java
+++ b/core/src/main/java/spotty/common/http/HttpHeaders.java
@@ -315,7 +315,7 @@ public HttpHeaders(HttpHeaders headers) {
/**
* add header
*
- * @param name header name
+ * @param name header name
* @param value header value
* @return this instance of headers
*/
@@ -360,39 +360,39 @@ public String get(String name) {
* remove header by name
*
* @param name header name
- * @return the previous header value associated with name, or
- * null if there was no header for given name.
+ * @return the previous header value associated with name, or
+ * null if there was no header for given name.
*/
public String remove(String name) {
return headers.remove(name);
}
/**
- * Returns true if this HttpHeaders contains a header for the specified name.
+ * Returns true if this HttpHeaders contains a header for the specified name.
*
* @param name header name
- * @return true if this HttpHeaders contains a header for the specified name.
+ * @return true if this HttpHeaders contains a header for the specified name.
*/
public boolean has(String name) {
return headers.containsKey(name);
}
/**
- * Returns false if this HttpHeaders contains no header for the specified name.
+ * Returns false if this HttpHeaders contains no header for the specified name.
*
* @param name header name
- * @return true if this HttpHeaders contains no header for the specified name.
+ * @return true if this HttpHeaders contains no header for the specified name.
*/
public boolean hasNot(String name) {
return !headers.containsKey(name);
}
/**
- * Returns true if this HttpHeaders contains a header for the specified name and header value is equal with given.
+ * Returns true if this HttpHeaders contains a header for the specified name and header value is equal with given.
*
- * @param name header name
+ * @param name header name
* @param value header value
- * @return true if this HttpHeaders contains a header for the specified name and header value is equal with given.
+ * @return true if this HttpHeaders contains a header for the specified name and header value is equal with given.
*/
public boolean hasAndEqual(String name, String value) {
final String header = headers.get(name);
@@ -413,18 +413,18 @@ public int size() {
}
/**
- * Returns true if this HttpHeaders contains no headers.
+ * Returns true if this HttpHeaders contains no headers.
*
- * @return true if this HttpHeaders contains no headers
+ * @return true if this HttpHeaders contains no headers
*/
public boolean isEmpty() {
return headers.isEmpty();
}
/**
- * Returns true if this HttpHeaders contains headers.
+ * Returns true if this HttpHeaders contains headers.
*
- * @return true if this HttpHeaders contains headers
+ * @return true if this HttpHeaders contains headers
*/
public boolean isNotEmpty() {
return headers.size() > 0;
diff --git a/core/src/main/java/spotty/common/response/ResponseHeadersWriter.java b/core/src/main/java/spotty/common/response/ResponseHeadersWriter.java
new file mode 100644
index 0000000..66a40f8
--- /dev/null
+++ b/core/src/main/java/spotty/common/response/ResponseHeadersWriter.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2022 - Alex Danilenko
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package spotty.common.response;
+
+import spotty.common.http.HttpHeaders;
+import spotty.common.stream.output.SpottyByteArrayOutputStream;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+public final class ResponseHeadersWriter {
+ private static final byte[] HEADER_SPLITTER = ": ".getBytes(UTF_8);
+ private static final byte[] SPACE = " ".getBytes(UTF_8);
+ private static final byte[] CONTENT_LENGTH = HttpHeaders.CONTENT_LENGTH.getBytes(UTF_8);
+ private static final byte[] CONTENT_TYPE = HttpHeaders.CONTENT_TYPE.getBytes(UTF_8);
+ private static final byte[] SET_COOKIE = HttpHeaders.SET_COOKIE.getBytes(UTF_8);
+
+ public static void write(SpottyByteArrayOutputStream writer, SpottyResponse response) {
+ writer.print(response.protocol().code); writer.write(SPACE); writer.print(response.status().toString());
+ writer.println();
+
+ writer.write(CONTENT_LENGTH); writer.write(HEADER_SPLITTER); writer.print(Integer.toString(response.contentLength()));
+ writer.println();
+
+ if (response.contentType() != null) {
+ writer.write(CONTENT_TYPE); writer.write(HEADER_SPLITTER); writer.print(response.contentType());
+ writer.println();
+ }
+
+ response.headers()
+ .forEach((name, value) -> {
+ writer.print(name); writer.write(HEADER_SPLITTER); writer.print(value);
+ writer.println();
+ });
+
+ response.cookies()
+ .forEach(cookie -> {
+ writer.write(SET_COOKIE); writer.write(HEADER_SPLITTER); writer.print(cookie.toString());
+ writer.println();
+ });
+
+ writer.println();
+ }
+
+}
diff --git a/core/src/main/java/spotty/common/response/ResponseWriter.java b/core/src/main/java/spotty/common/response/ResponseWriter.java
deleted file mode 100644
index 3c01118..0000000
--- a/core/src/main/java/spotty/common/response/ResponseWriter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2022 - Alex Danilenko
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package spotty.common.response;
-
-import spotty.common.http.HttpHeaders;
-import spotty.common.stream.output.SpottyByteArrayOutputStream;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-/**
- * Single thread use only
- */
-public final class ResponseWriter {
- private static final byte[] HEADER_SPLITTER = ": ".getBytes(UTF_8);
- private static final byte[] SPACE = " ".getBytes(UTF_8);
- private static final byte[] CONTENT_LENGTH = HttpHeaders.CONTENT_LENGTH.getBytes(UTF_8);
- private static final byte[] CONTENT_TYPE = HttpHeaders.CONTENT_TYPE.getBytes(UTF_8);
- private static final byte[] SET_COOKIE = HttpHeaders.SET_COOKIE.getBytes(UTF_8);
-
- private final SpottyByteArrayOutputStream writer = new SpottyByteArrayOutputStream(2048);
-
- public byte[] write(SpottyResponse response) {
- try {
- writer.print(response.protocol().code); writer.write(SPACE); writer.print(response.status().toString());
- writer.println();
-
- writer.write(CONTENT_LENGTH); writer.write(HEADER_SPLITTER); writer.print(Integer.toString(response.contentLength()));
- writer.println();
-
- if (response.contentType() != null) {
- writer.write(CONTENT_TYPE); writer.write(HEADER_SPLITTER); writer.print(response.contentType());
- writer.println();
- }
-
- response.headers()
- .forEach((name, value) -> {
- writer.print(name); writer.write(HEADER_SPLITTER); writer.print(value);
- writer.println();
- });
-
- response.cookies()
- .forEach(cookie -> {
- writer.write(SET_COOKIE); writer.write(HEADER_SPLITTER); writer.print(cookie.toString());
- writer.println();
- });
-
- writer.println();
-
- if (response.body() != null) {
- writer.write(response.body());
- }
-
- return writer.toByteArray();
- } finally {
- writer.reset();
- }
- }
-
-}
diff --git a/core/src/main/java/spotty/common/session/Session.java b/core/src/main/java/spotty/common/session/Session.java
index a9692be..195deec 100644
--- a/core/src/main/java/spotty/common/session/Session.java
+++ b/core/src/main/java/spotty/common/session/Session.java
@@ -112,7 +112,7 @@ public Session putIfAbsent(Object key, Object value) {
*
* @param key key with which the specified value is to be associated
* @param mapper the function to compute a value
- * @param return type
+ * @param return type
* @return the current (existing or computed) value associated with
* the specified key, or null if the computed value is null
*/
@@ -132,7 +132,7 @@ public T computeIfAbsent(Object key, Function