michael-o commented on code in PR #370: URL: https://github.com/apache/httpcomponents-client/pull/370#discussion_r882932243
########## httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java: ########## @@ -30,39 +30,41 @@ import org.apache.hc.core5.annotation.Internal; -import java.nio.charset.StandardCharsets; - import static java.util.Base64.getEncoder; import static java.util.Base64.getMimeDecoder; /** * Provide implementations of the Base64 conversion methods from commons-codec, delegating to the Java Base64 * implementation. * <p> + * * <ul>Only the features currently used by http-client are implemented here rather than all the features of commons-coded</ul> Review Comment: Commons Codec ########## httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java: ########## @@ -30,39 +30,41 @@ import org.apache.hc.core5.annotation.Internal; -import java.nio.charset.StandardCharsets; - import static java.util.Base64.getEncoder; import static java.util.Base64.getMimeDecoder; /** * Provide implementations of the Base64 conversion methods from commons-codec, delegating to the Java Base64 * implementation. * <p> + * * <ul>Only the features currently used by http-client are implemented here rather than all the features of commons-coded</ul> Review Comment: HttpClient ########## httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java: ########## @@ -30,39 +30,41 @@ import org.apache.hc.core5.annotation.Internal; -import java.nio.charset.StandardCharsets; - import static java.util.Base64.getEncoder; import static java.util.Base64.getMimeDecoder; /** * Provide implementations of the Base64 conversion methods from commons-codec, delegating to the Java Base64 * implementation. * <p> + * * <ul>Only the features currently used by http-client are implemented here rather than all the features of commons-coded</ul> * Notes: * <p> * <ul>commons-codec accepts null inputs, so this is also accepted here. This is not done in the Java 8 implementation</ul> - * <ul>decoding invalid inputs returns an empty value. The Java 8 implementation throws an exception, which is caught here</ul> - * <ul>commons-codec decoders accept both standard and url-safe variants of input. This needs to be remapped for Java 8, as it - * will accept either one or the other, but not both. This is likely a rarely-needed requirement, but is provided to avoid - * compatibility surprises. + * <ul>Decoding invalid inputs returns an empty value. The Java 8 implementation throws an exception, which is caught here</ul> + * <ul>commons-codec decoders accept both standard and url-safe variants of input. As this is not a requirement for + * httpcommons-client, this is NOT implemented here. * </ul> - * <ul>Only the features currently used by http-client are implemented here rather than all the features of commons-coded</ul> + * <p> + * This class is intended as in interim convenience. Any new code should just use `java.util.Base64` directly. */ @Internal public class Base64 { + private static final Base64 CODEC = new Base64(); private static final byte[] EMPTY_BYTES = new byte[0]; /** - * Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode. + * Return an instance of the Base64 codec that use the regular Base64 alphabet + * (as opposed to the URL-safe alphabet). Note that unlike the commons-codec version, + * thus class will NOT decode characters from URL-safe alphabet. */ public Base64() { } /** - * Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode. + * Creates a Base64 codec used for decoding and encoding in URL-unsafe mode. * <p> - * As http-client never uses a non-zero length, this feature is not implemented here. + * As httpcommons-client never uses a non-zero length, this feature is not implemented here. Review Comment: HttpClient ########## httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestBase64.java: ########## @@ -108,21 +108,6 @@ void decodeUnpadded() { checkDecode("BBBBAAA"); } - @Test - void decodeUrlSafe() { - final char underscore = '_'; - final char minus = '-'; - - checkDecode(fourOf(minus)); - checkDecode(fourOf(underscore)); - } - - @Test - void mixedUrlAndRegularEncoded() { - checkDecode("++__"); - checkDecode("--//"); - } - Review Comment: I don't even know how much it makes sense to test here. At most our wrapper, but not Base64 itself because it is not provided by us. ########## httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java: ########## @@ -30,39 +30,41 @@ import org.apache.hc.core5.annotation.Internal; -import java.nio.charset.StandardCharsets; - import static java.util.Base64.getEncoder; import static java.util.Base64.getMimeDecoder; /** * Provide implementations of the Base64 conversion methods from commons-codec, delegating to the Java Base64 * implementation. * <p> + * * <ul>Only the features currently used by http-client are implemented here rather than all the features of commons-coded</ul> * Notes: * <p> * <ul>commons-codec accepts null inputs, so this is also accepted here. This is not done in the Java 8 implementation</ul> - * <ul>decoding invalid inputs returns an empty value. The Java 8 implementation throws an exception, which is caught here</ul> - * <ul>commons-codec decoders accept both standard and url-safe variants of input. This needs to be remapped for Java 8, as it - * will accept either one or the other, but not both. This is likely a rarely-needed requirement, but is provided to avoid - * compatibility surprises. + * <ul>Decoding invalid inputs returns an empty value. The Java 8 implementation throws an exception, which is caught here</ul> Review Comment: invalid input returns ########## httpclient5/src/main/java/org/apache/hc/client5/http/utils/Base64.java: ########## @@ -30,39 +30,41 @@ import org.apache.hc.core5.annotation.Internal; -import java.nio.charset.StandardCharsets; - import static java.util.Base64.getEncoder; import static java.util.Base64.getMimeDecoder; /** * Provide implementations of the Base64 conversion methods from commons-codec, delegating to the Java Base64 * implementation. * <p> + * * <ul>Only the features currently used by http-client are implemented here rather than all the features of commons-coded</ul> * Notes: * <p> * <ul>commons-codec accepts null inputs, so this is also accepted here. This is not done in the Java 8 implementation</ul> - * <ul>decoding invalid inputs returns an empty value. The Java 8 implementation throws an exception, which is caught here</ul> - * <ul>commons-codec decoders accept both standard and url-safe variants of input. This needs to be remapped for Java 8, as it - * will accept either one or the other, but not both. This is likely a rarely-needed requirement, but is provided to avoid - * compatibility surprises. + * <ul>Decoding invalid inputs returns an empty value. The Java 8 implementation throws an exception, which is caught here</ul> + * <ul>commons-codec decoders accept both standard and url-safe variants of input. As this is not a requirement for + * httpcommons-client, this is NOT implemented here. Review Comment: 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-unsubscr...@hc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org