You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "ok2c (via GitHub)" <gi...@apache.org> on 2024/01/30 14:22:54 UTC

[PR] HTTPCLIENT-2070: Auth cache to no longer rely on Java serialization for auth state caching [httpcomponents-client]

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

   No more Java serialization in HttpClient


-- 
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


Re: [PR] HTTPCLIENT-2070: Auth cache to no longer rely on Java serialization for auth state caching [httpcomponents-client]

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

   @arturobernalg Please take a look.


-- 
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


Re: [PR] HTTPCLIENT-2070: Auth cache to no longer rely on Java serialization for auth state caching [httpcomponents-client]

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


##########
httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java:
##########
@@ -232,27 +228,47 @@ public String generateAuthResponse(
         return StandardAuthScheme.BASIC + " " + new String(encodedCreds, 0, encodedCreds.length, StandardCharsets.US_ASCII);
     }
 
-    private void writeObject(final ObjectOutputStream out) throws IOException {
-        out.defaultWriteObject();
-        out.writeUTF(this.defaultCharset.name());
-    }
-
-    @SuppressWarnings("unchecked")
-    private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
-        in.defaultReadObject();
-        try {
-            this.defaultCharset = Charset.forName(in.readUTF());
-        } catch (final UnsupportedCharsetException ex) {
-            this.defaultCharset = StandardCharsets.UTF_8;
+    @Override
+    public State store() {
+        if (complete) {
+            return new State(new HashMap<>(paramMap), credentials);
+        } else {
+            return null;
         }
     }
 
-    private void readObjectNoData() {
+    @Override
+    public void restore(final State state) {
+        if (state != null) {
+            paramMap.clear();
+            paramMap.putAll(state.params);
+            credentials = state.credentials;
+            complete = true;
+        }
     }
 
     @Override
     public String toString() {
         return getName() + this.paramMap;
     }
 
+    @Internal
+    public static class State {
+
+        final Map<String, String> params;

Review Comment:
   I assume this variables  are not private due to its internal scope.



##########
httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BearerScheme.java:
##########
@@ -161,9 +163,49 @@ public String generateAuthResponse(
         return StandardAuthScheme.BEARER + " " + bearerToken.getToken();
     }
 
+    @Override
+    public State store() {
+        if (complete) {
+            return new State(new HashMap<>(paramMap), bearerToken);
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public void restore(final State state) {
+        if (state != null) {
+            paramMap.clear();
+            paramMap.putAll(state.params);
+            bearerToken = state.bearerToken;
+            complete = true;
+        }
+    }
+
     @Override
     public String toString() {
         return getName() + this.paramMap;
     }
 
+    @Internal
+    public static class State {
+
+        final Map<String, String> params;

Review Comment:
   I assume this variables  are not private due to its internal scope.



-- 
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


Re: [PR] HTTPCLIENT-2070: Auth cache to no longer rely on Java serialization for auth state caching [httpcomponents-client]

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


##########
httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java:
##########
@@ -232,27 +228,47 @@ public String generateAuthResponse(
         return StandardAuthScheme.BASIC + " " + new String(encodedCreds, 0, encodedCreds.length, StandardCharsets.US_ASCII);
     }
 
-    private void writeObject(final ObjectOutputStream out) throws IOException {
-        out.defaultWriteObject();
-        out.writeUTF(this.defaultCharset.name());
-    }
-
-    @SuppressWarnings("unchecked")
-    private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
-        in.defaultReadObject();
-        try {
-            this.defaultCharset = Charset.forName(in.readUTF());
-        } catch (final UnsupportedCharsetException ex) {
-            this.defaultCharset = StandardCharsets.UTF_8;
+    @Override
+    public State store() {
+        if (complete) {
+            return new State(new HashMap<>(paramMap), credentials);
+        } else {
+            return null;
         }
     }
 
-    private void readObjectNoData() {
+    @Override
+    public void restore(final State state) {
+        if (state != null) {
+            paramMap.clear();
+            paramMap.putAll(state.params);
+            credentials = state.credentials;
+            complete = true;
+        }
     }
 
     @Override
     public String toString() {
         return getName() + this.paramMap;
     }
 
+    @Internal
+    public static class State {
+
+        final Map<String, String> params;

Review Comment:
   @arturobernalg Correct.



-- 
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


Re: [PR] HTTPCLIENT-2070: Auth cache to no longer rely on Java serialization for auth state caching [httpcomponents-client]

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


-- 
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