You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "arturobernalg (via GitHub)" <gi...@apache.org> on 2023/03/28 11:59:19 UTC

[GitHub] [httpcomponents-client] arturobernalg opened a new pull request, #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

arturobernalg opened a new pull request, #429:
URL: https://github.com/apache/httpcomponents-client/pull/429

   
   Improve HttpByteArrayCacheEntrySerializer class:
   
   - Add new method to serialize and deserialize cache entries using HTTP response and request objects.
   - Improve performance by optimizing buffer size and output stream usage.
   - Add escape headers method to escape headers in the HTTP response.
   - Add metadata pseudo headers to the HTTP response headers, including storage key, response date, request date, no content, variant map key, and variant map value.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] arturobernalg commented on a diff in pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "arturobernalg (via GitHub)" <gi...@apache.org>.
arturobernalg commented on code in PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429#discussion_r1154321331


##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java:
##########
@@ -81,14 +115,65 @@ public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializ
     private static final String SC_HEADER_NAME_NO_CONTENT = SC_CACHE_ENTRY_PREFIX + "no-content";
     private static final String SC_HEADER_NAME_VARIANT_MAP_KEY = SC_CACHE_ENTRY_PREFIX + "varmap-key";
     private static final String SC_HEADER_NAME_VARIANT_MAP_VALUE = SC_CACHE_ENTRY_PREFIX + "varmap-val";
-
     private static final String SC_CACHE_ENTRY_PRESERVE_PREFIX = SC_CACHE_ENTRY_PREFIX + "esc-";
 
-    private static final int BUFFER_SIZE = 8192;
 
+    /**
+     * The generator used to generate cached HTTP responses.
+     */
+    private final CachedHttpResponseGenerator cachedHttpResponseGenerator;
+
+    /**
+     * The size of the buffer used for reading/writing data.
+     */
+    private final int bufferSize;
+
+    /**
+     * Use the default, ASCII-only encoder for HTTP protocol and header values.
+     * It's the only thing that's widely used, and it's not worth it to support anything else.
+     */
+    private final SessionOutputBuffer outputBuffer;

Review Comment:
   @ok2c 
   You're correct. The SessionOutputBuffer cannot be an instance variable since it is not stateless. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] ok2c commented on pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "ok2c (via GitHub)" <gi...@apache.org>.
ok2c commented on PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429#issuecomment-1489959364

   @arturobernalg Overall looks good. Could you please mark `ByteArrayCacheEntrySerializer` as deprecated and reference the new default implementation as its replacement? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] arturobernalg commented on a diff in pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "arturobernalg (via GitHub)" <gi...@apache.org>.
arturobernalg commented on code in PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429#discussion_r1154321331


##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java:
##########
@@ -81,14 +115,65 @@ public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializ
     private static final String SC_HEADER_NAME_NO_CONTENT = SC_CACHE_ENTRY_PREFIX + "no-content";
     private static final String SC_HEADER_NAME_VARIANT_MAP_KEY = SC_CACHE_ENTRY_PREFIX + "varmap-key";
     private static final String SC_HEADER_NAME_VARIANT_MAP_VALUE = SC_CACHE_ENTRY_PREFIX + "varmap-val";
-
     private static final String SC_CACHE_ENTRY_PRESERVE_PREFIX = SC_CACHE_ENTRY_PREFIX + "esc-";
 
-    private static final int BUFFER_SIZE = 8192;
 
+    /**
+     * The generator used to generate cached HTTP responses.
+     */
+    private final CachedHttpResponseGenerator cachedHttpResponseGenerator;
+
+    /**
+     * The size of the buffer used for reading/writing data.
+     */
+    private final int bufferSize;
+
+    /**
+     * Use the default, ASCII-only encoder for HTTP protocol and header values.
+     * It's the only thing that's widely used, and it's not worth it to support anything else.
+     */
+    private final SessionOutputBuffer outputBuffer;

Review Comment:
   done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] michael-o commented on a diff in pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429#discussion_r1154089887


##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java:
##########
@@ -42,36 +44,68 @@
 import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
 import org.apache.hc.client5.http.cache.Resource;
 import org.apache.hc.client5.http.cache.ResourceIOException;
-import org.apache.hc.core5.annotation.Experimental;
-import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.config.Http1Config;
 import org.apache.hc.core5.http.impl.io.AbstractMessageParser;
 import org.apache.hc.core5.http.impl.io.AbstractMessageWriter;
 import org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser;
 import org.apache.hc.core5.http.impl.io.SessionInputBufferImpl;
 import org.apache.hc.core5.http.impl.io.SessionOutputBufferImpl;
 import org.apache.hc.core5.http.io.SessionInputBuffer;
 import org.apache.hc.core5.http.io.SessionOutputBuffer;
+import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.http.message.BasicLineFormatter;
+import org.apache.hc.core5.http.message.HeaderGroup;
+import org.apache.hc.core5.http.message.LazyLineParser;
 import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TimeValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Cache serializer and deserializer that uses an HTTP-like format.
+ * Serializes and deserializes byte arrays into HTTP cache entries using a default buffer size of 8192 bytes.
+ * The cache entries contain an HTTP response generated from the byte array data, which can be used to generate
+ * HTTP responses for cache hits.
+ * <p>
+ * This implementation uses the Apache HttpComponents library to perform the serialization and deserialization.
+ * <p>
+ * To serialize a byte array into an HTTP cache entry, use the {@link #serialize(HttpCacheStorageEntry)} method. To deserialize an HTTP cache
+ * entry into a byte array, use the {@link #deserialize(byte[])} method.
+ * <p>
+ * This class implements the {@link HttpCacheEntrySerializer} interface, which defines the contract for HTTP cache
+ * entry serialization and deserialization. It also includes a default buffer size of 8192 bytes, which can be
+ * overridden by specifying a different buffer size in the constructor.
+ * <p>
+ * Note that this implementation only supports HTTP responses and does not support HTTP requests or any other types of
+ * HTTP messages.
  *
- * Existing libraries for reading and writing HTTP are used, and metadata is encoded into HTTP
- * pseudo-headers for storage.
+ * @since 5.3
  */
-@Experimental
+@Contract(threading = ThreadingBehavior.STATELESS)
 public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializer<byte[]> {
-    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer();
+
+    private static final Logger LOG = LoggerFactory.getLogger(HttpByteArrayCacheEntrySerializer.class);
+
+    /**
+     * The default buffer size used for I/O operations, set to 8192 bytes.
+     */
+    private static final int DEFAULT_BUFFER_SIZE = 8192;
+
+    /**
+     * Singleton instance of this class.
+     */
+    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer(DEFAULT_BUFFER_SIZE);
+
 
     private static final String SC_CACHE_ENTRY_PREFIX = "hc-";

Review Comment:
   FTR: https://tonyxu.io/posts/2018/http-deprecate-x-prefix/



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] arturobernalg commented on a diff in pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "arturobernalg (via GitHub)" <gi...@apache.org>.
arturobernalg commented on code in PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429#discussion_r1154320931


##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java:
##########
@@ -42,36 +44,68 @@
 import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
 import org.apache.hc.client5.http.cache.Resource;
 import org.apache.hc.client5.http.cache.ResourceIOException;
-import org.apache.hc.core5.annotation.Experimental;
-import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.config.Http1Config;
 import org.apache.hc.core5.http.impl.io.AbstractMessageParser;
 import org.apache.hc.core5.http.impl.io.AbstractMessageWriter;
 import org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser;
 import org.apache.hc.core5.http.impl.io.SessionInputBufferImpl;
 import org.apache.hc.core5.http.impl.io.SessionOutputBufferImpl;
 import org.apache.hc.core5.http.io.SessionInputBuffer;
 import org.apache.hc.core5.http.io.SessionOutputBuffer;
+import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.http.message.BasicLineFormatter;
+import org.apache.hc.core5.http.message.HeaderGroup;
+import org.apache.hc.core5.http.message.LazyLineParser;
 import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TimeValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Cache serializer and deserializer that uses an HTTP-like format.
+ * Serializes and deserializes byte arrays into HTTP cache entries using a default buffer size of 8192 bytes.
+ * The cache entries contain an HTTP response generated from the byte array data, which can be used to generate
+ * HTTP responses for cache hits.
+ * <p>
+ * This implementation uses the Apache HttpComponents library to perform the serialization and deserialization.
+ * <p>
+ * To serialize a byte array into an HTTP cache entry, use the {@link #serialize(HttpCacheStorageEntry)} method. To deserialize an HTTP cache
+ * entry into a byte array, use the {@link #deserialize(byte[])} method.
+ * <p>
+ * This class implements the {@link HttpCacheEntrySerializer} interface, which defines the contract for HTTP cache
+ * entry serialization and deserialization. It also includes a default buffer size of 8192 bytes, which can be
+ * overridden by specifying a different buffer size in the constructor.
+ * <p>
+ * Note that this implementation only supports HTTP responses and does not support HTTP requests or any other types of
+ * HTTP messages.
  *
- * Existing libraries for reading and writing HTTP are used, and metadata is encoded into HTTP
- * pseudo-headers for storage.
+ * @since 5.3
  */
-@Experimental
+@Contract(threading = ThreadingBehavior.STATELESS)
 public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializer<byte[]> {
-    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer();
+
+    private static final Logger LOG = LoggerFactory.getLogger(HttpByteArrayCacheEntrySerializer.class);
+
+    /**
+     * The default buffer size used for I/O operations, set to 8192 bytes.
+     */
+    private static final int DEFAULT_BUFFER_SIZE = 8192;
+
+    /**
+     * Singleton instance of this class.
+     */
+    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer(DEFAULT_BUFFER_SIZE);
+
 
     private static final String SC_CACHE_ENTRY_PREFIX = "hc-";

Review Comment:
   Yep, look like is Deprecating the "X-" Prefix and Similar Constructs  in Application Protocols in the rfc6648
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] michael-o commented on a diff in pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429#discussion_r1154089887


##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java:
##########
@@ -42,36 +44,68 @@
 import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
 import org.apache.hc.client5.http.cache.Resource;
 import org.apache.hc.client5.http.cache.ResourceIOException;
-import org.apache.hc.core5.annotation.Experimental;
-import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.config.Http1Config;
 import org.apache.hc.core5.http.impl.io.AbstractMessageParser;
 import org.apache.hc.core5.http.impl.io.AbstractMessageWriter;
 import org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser;
 import org.apache.hc.core5.http.impl.io.SessionInputBufferImpl;
 import org.apache.hc.core5.http.impl.io.SessionOutputBufferImpl;
 import org.apache.hc.core5.http.io.SessionInputBuffer;
 import org.apache.hc.core5.http.io.SessionOutputBuffer;
+import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.http.message.BasicLineFormatter;
+import org.apache.hc.core5.http.message.HeaderGroup;
+import org.apache.hc.core5.http.message.LazyLineParser;
 import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TimeValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Cache serializer and deserializer that uses an HTTP-like format.
+ * Serializes and deserializes byte arrays into HTTP cache entries using a default buffer size of 8192 bytes.
+ * The cache entries contain an HTTP response generated from the byte array data, which can be used to generate
+ * HTTP responses for cache hits.
+ * <p>
+ * This implementation uses the Apache HttpComponents library to perform the serialization and deserialization.
+ * <p>
+ * To serialize a byte array into an HTTP cache entry, use the {@link #serialize(HttpCacheStorageEntry)} method. To deserialize an HTTP cache
+ * entry into a byte array, use the {@link #deserialize(byte[])} method.
+ * <p>
+ * This class implements the {@link HttpCacheEntrySerializer} interface, which defines the contract for HTTP cache
+ * entry serialization and deserialization. It also includes a default buffer size of 8192 bytes, which can be
+ * overridden by specifying a different buffer size in the constructor.
+ * <p>
+ * Note that this implementation only supports HTTP responses and does not support HTTP requests or any other types of
+ * HTTP messages.
  *
- * Existing libraries for reading and writing HTTP are used, and metadata is encoded into HTTP
- * pseudo-headers for storage.
+ * @since 5.3
  */
-@Experimental
+@Contract(threading = ThreadingBehavior.STATELESS)
 public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializer<byte[]> {
-    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer();
+
+    private static final Logger LOG = LoggerFactory.getLogger(HttpByteArrayCacheEntrySerializer.class);
+
+    /**
+     * The default buffer size used for I/O operations, set to 8192 bytes.
+     */
+    private static final int DEFAULT_BUFFER_SIZE = 8192;
+
+    /**
+     * Singleton instance of this class.
+     */
+    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer(DEFAULT_BUFFER_SIZE);
+
 
     private static final String SC_CACHE_ENTRY_PREFIX = "hc-";

Review Comment:
   FTR: https://tonyxu.io/posts/2018/http-deprecate-x-prefix/, ultimately Request for Comments: 6648 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] ok2c commented on a diff in pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "ok2c (via GitHub)" <gi...@apache.org>.
ok2c commented on code in PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429#discussion_r1154065239


##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java:
##########
@@ -42,36 +44,68 @@
 import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
 import org.apache.hc.client5.http.cache.Resource;
 import org.apache.hc.client5.http.cache.ResourceIOException;
-import org.apache.hc.core5.annotation.Experimental;
-import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.config.Http1Config;
 import org.apache.hc.core5.http.impl.io.AbstractMessageParser;
 import org.apache.hc.core5.http.impl.io.AbstractMessageWriter;
 import org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser;
 import org.apache.hc.core5.http.impl.io.SessionInputBufferImpl;
 import org.apache.hc.core5.http.impl.io.SessionOutputBufferImpl;
 import org.apache.hc.core5.http.io.SessionInputBuffer;
 import org.apache.hc.core5.http.io.SessionOutputBuffer;
+import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.http.message.BasicLineFormatter;
+import org.apache.hc.core5.http.message.HeaderGroup;
+import org.apache.hc.core5.http.message.LazyLineParser;
 import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TimeValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Cache serializer and deserializer that uses an HTTP-like format.
+ * Serializes and deserializes byte arrays into HTTP cache entries using a default buffer size of 8192 bytes.
+ * The cache entries contain an HTTP response generated from the byte array data, which can be used to generate
+ * HTTP responses for cache hits.
+ * <p>
+ * This implementation uses the Apache HttpComponents library to perform the serialization and deserialization.
+ * <p>
+ * To serialize a byte array into an HTTP cache entry, use the {@link #serialize(HttpCacheStorageEntry)} method. To deserialize an HTTP cache
+ * entry into a byte array, use the {@link #deserialize(byte[])} method.
+ * <p>
+ * This class implements the {@link HttpCacheEntrySerializer} interface, which defines the contract for HTTP cache
+ * entry serialization and deserialization. It also includes a default buffer size of 8192 bytes, which can be
+ * overridden by specifying a different buffer size in the constructor.
+ * <p>
+ * Note that this implementation only supports HTTP responses and does not support HTTP requests or any other types of
+ * HTTP messages.
  *
- * Existing libraries for reading and writing HTTP are used, and metadata is encoded into HTTP
- * pseudo-headers for storage.
+ * @since 5.3
  */
-@Experimental
+@Contract(threading = ThreadingBehavior.STATELESS)
 public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializer<byte[]> {
-    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer();
+
+    private static final Logger LOG = LoggerFactory.getLogger(HttpByteArrayCacheEntrySerializer.class);
+
+    /**
+     * The default buffer size used for I/O operations, set to 8192 bytes.
+     */
+    private static final int DEFAULT_BUFFER_SIZE = 8192;
+
+    /**
+     * Singleton instance of this class.
+     */
+    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer(DEFAULT_BUFFER_SIZE);
+
 
     private static final String SC_CACHE_ENTRY_PREFIX = "hc-";

Review Comment:
   @michael-o @arturobernalg Hmm. I was not aware. Feel free to disregard my comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] michael-o commented on a diff in pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429#discussion_r1154062956


##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java:
##########
@@ -42,36 +44,68 @@
 import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
 import org.apache.hc.client5.http.cache.Resource;
 import org.apache.hc.client5.http.cache.ResourceIOException;
-import org.apache.hc.core5.annotation.Experimental;
-import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.config.Http1Config;
 import org.apache.hc.core5.http.impl.io.AbstractMessageParser;
 import org.apache.hc.core5.http.impl.io.AbstractMessageWriter;
 import org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser;
 import org.apache.hc.core5.http.impl.io.SessionInputBufferImpl;
 import org.apache.hc.core5.http.impl.io.SessionOutputBufferImpl;
 import org.apache.hc.core5.http.io.SessionInputBuffer;
 import org.apache.hc.core5.http.io.SessionOutputBuffer;
+import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.http.message.BasicLineFormatter;
+import org.apache.hc.core5.http.message.HeaderGroup;
+import org.apache.hc.core5.http.message.LazyLineParser;
 import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TimeValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Cache serializer and deserializer that uses an HTTP-like format.
+ * Serializes and deserializes byte arrays into HTTP cache entries using a default buffer size of 8192 bytes.
+ * The cache entries contain an HTTP response generated from the byte array data, which can be used to generate
+ * HTTP responses for cache hits.
+ * <p>
+ * This implementation uses the Apache HttpComponents library to perform the serialization and deserialization.
+ * <p>
+ * To serialize a byte array into an HTTP cache entry, use the {@link #serialize(HttpCacheStorageEntry)} method. To deserialize an HTTP cache
+ * entry into a byte array, use the {@link #deserialize(byte[])} method.
+ * <p>
+ * This class implements the {@link HttpCacheEntrySerializer} interface, which defines the contract for HTTP cache
+ * entry serialization and deserialization. It also includes a default buffer size of 8192 bytes, which can be
+ * overridden by specifying a different buffer size in the constructor.
+ * <p>
+ * Note that this implementation only supports HTTP responses and does not support HTTP requests or any other types of
+ * HTTP messages.
  *
- * Existing libraries for reading and writing HTTP are used, and metadata is encoded into HTTP
- * pseudo-headers for storage.
+ * @since 5.3
  */
-@Experimental
+@Contract(threading = ThreadingBehavior.STATELESS)
 public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializer<byte[]> {
-    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer();
+
+    private static final Logger LOG = LoggerFactory.getLogger(HttpByteArrayCacheEntrySerializer.class);
+
+    /**
+     * The default buffer size used for I/O operations, set to 8192 bytes.
+     */
+    private static final int DEFAULT_BUFFER_SIZE = 8192;
+
+    /**
+     * Singleton instance of this class.
+     */
+    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer(DEFAULT_BUFFER_SIZE);
+
 
     private static final String SC_CACHE_ENTRY_PREFIX = "hc-";

Review Comment:
   This recommendation is obsolete for many years.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] arturobernalg commented on pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "arturobernalg (via GitHub)" <gi...@apache.org>.
arturobernalg commented on PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429#issuecomment-1490093869

   > @arturobernalg Overall looks good. Could you please mark `ByteArrayCacheEntrySerializer` as deprecated and reference the new default implementation as its replacement?
   
   @ok2c  what about now?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] ok2c commented on a diff in pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "ok2c (via GitHub)" <gi...@apache.org>.
ok2c commented on code in PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429#discussion_r1154034009


##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java:
##########
@@ -42,36 +44,68 @@
 import org.apache.hc.client5.http.cache.HttpCacheStorageEntry;
 import org.apache.hc.client5.http.cache.Resource;
 import org.apache.hc.client5.http.cache.ResourceIOException;
-import org.apache.hc.core5.annotation.Experimental;
-import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.config.Http1Config;
 import org.apache.hc.core5.http.impl.io.AbstractMessageParser;
 import org.apache.hc.core5.http.impl.io.AbstractMessageWriter;
 import org.apache.hc.core5.http.impl.io.DefaultHttpResponseParser;
 import org.apache.hc.core5.http.impl.io.SessionInputBufferImpl;
 import org.apache.hc.core5.http.impl.io.SessionOutputBufferImpl;
 import org.apache.hc.core5.http.io.SessionInputBuffer;
 import org.apache.hc.core5.http.io.SessionOutputBuffer;
+import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
 import org.apache.hc.core5.http.message.BasicLineFormatter;
+import org.apache.hc.core5.http.message.HeaderGroup;
+import org.apache.hc.core5.http.message.LazyLineParser;
 import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TimeValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Cache serializer and deserializer that uses an HTTP-like format.
+ * Serializes and deserializes byte arrays into HTTP cache entries using a default buffer size of 8192 bytes.
+ * The cache entries contain an HTTP response generated from the byte array data, which can be used to generate
+ * HTTP responses for cache hits.
+ * <p>
+ * This implementation uses the Apache HttpComponents library to perform the serialization and deserialization.
+ * <p>
+ * To serialize a byte array into an HTTP cache entry, use the {@link #serialize(HttpCacheStorageEntry)} method. To deserialize an HTTP cache
+ * entry into a byte array, use the {@link #deserialize(byte[])} method.
+ * <p>
+ * This class implements the {@link HttpCacheEntrySerializer} interface, which defines the contract for HTTP cache
+ * entry serialization and deserialization. It also includes a default buffer size of 8192 bytes, which can be
+ * overridden by specifying a different buffer size in the constructor.
+ * <p>
+ * Note that this implementation only supports HTTP responses and does not support HTTP requests or any other types of
+ * HTTP messages.
  *
- * Existing libraries for reading and writing HTTP are used, and metadata is encoded into HTTP
- * pseudo-headers for storage.
+ * @since 5.3
  */
-@Experimental
+@Contract(threading = ThreadingBehavior.STATELESS)
 public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializer<byte[]> {
-    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer();
+
+    private static final Logger LOG = LoggerFactory.getLogger(HttpByteArrayCacheEntrySerializer.class);
+
+    /**
+     * The default buffer size used for I/O operations, set to 8192 bytes.
+     */
+    private static final int DEFAULT_BUFFER_SIZE = 8192;
+
+    /**
+     * Singleton instance of this class.
+     */
+    public static final HttpByteArrayCacheEntrySerializer INSTANCE = new HttpByteArrayCacheEntrySerializer(DEFAULT_BUFFER_SIZE);
+
 
     private static final String SC_CACHE_ENTRY_PREFIX = "hc-";

Review Comment:
   @arturobernalg I suggest we use recommended naming convention and prefix our custom headers with `x-`:
   `SC_CACHE_ENTRY_PREFIX = "x-hc-";`



##########
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializer.java:
##########
@@ -81,14 +115,65 @@ public class HttpByteArrayCacheEntrySerializer implements HttpCacheEntrySerializ
     private static final String SC_HEADER_NAME_NO_CONTENT = SC_CACHE_ENTRY_PREFIX + "no-content";
     private static final String SC_HEADER_NAME_VARIANT_MAP_KEY = SC_CACHE_ENTRY_PREFIX + "varmap-key";
     private static final String SC_HEADER_NAME_VARIANT_MAP_VALUE = SC_CACHE_ENTRY_PREFIX + "varmap-val";
-
     private static final String SC_CACHE_ENTRY_PRESERVE_PREFIX = SC_CACHE_ENTRY_PREFIX + "esc-";
 
-    private static final int BUFFER_SIZE = 8192;
 
+    /**
+     * The generator used to generate cached HTTP responses.
+     */
+    private final CachedHttpResponseGenerator cachedHttpResponseGenerator;
+
+    /**
+     * The size of the buffer used for reading/writing data.
+     */
+    private final int bufferSize;
+
+    /**
+     * Use the default, ASCII-only encoder for HTTP protocol and header values.
+     * It's the only thing that's widely used, and it's not worth it to support anything else.
+     */
+    private final SessionOutputBuffer outputBuffer;

Review Comment:
   @arturobernalg Careful here. The class is expected to be stateless by the contract, but `SessionOutputBuffer` is not. It can not be an instance variable! You need to make it local.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] ok2c merged pull request #429: Improve HttpByteArrayCacheEntrySerializer class by adding new methods and enhancing performance.

Posted by "ok2c (via GitHub)" <gi...@apache.org>.
ok2c merged PR #429:
URL: https://github.com/apache/httpcomponents-client/pull/429


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org