Skip to content

Commit 2b21d08

Browse files
committed
Improve WebClientOptions javadoc.
1 parent 72b3b06 commit 2b21d08

File tree

2 files changed

+116
-53
lines changed

2 files changed

+116
-53
lines changed

src/changes/changes.xml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,34 @@
77
</properties>
88

99
<body>
10-
<release version="4.15.0" date="August xx, 2025" description="Chrome/Edge 139, Firefox 141, Bugfixes">
10+
<release version="4.15.0" date="August 17, 2025" description="Chrome/Edge 139, Firefox 141, core-js, Bugfixes">
11+
<action type="update" dev="rbri">
12+
Improve WebClientOptions javadoc.
13+
</action>
14+
<action type="fix" dev="RhinoTeam" issue="#1001">
15+
core-js: Fix two more regession from the Interpreter refactoring. Various combinations
16+
of apply/bind/call now working again.
17+
</action>
1118
<action type="update" dev="rbri">
1219
websocket-client: jetty updated to 9.4.58.v20250814.
1320
</action>
14-
<action type="add" dev="RhinoTeam">
21+
<action type="fix" dev="RhinoTeam">
1522
core-js: Fix a regression regarding optional chaining operators.
1623
</action>
24+
<action type="fix" dev="rbri">
25+
neko: Always call detectEncoding() to skip bom in case we got an input stream with bom and an encoding.
26+
</action>
27+
<action type="update" dev="rbri">
28+
neko: increase PlaybackInputStream buffer size
29+
</action>
30+
<action type="add" dev="rbri">
31+
neko: addNekoSAXParser Factory added
32+
</action>
1733
<action type="add" dev="rbri">
1834
WebClient option pageRefreshLimit added. Refresh handling changed to support a clear limit.
1935
The initial value is 72 to be backward compatible.
2036
</action>
21-
<action type="add" dev="RhinoTeam">
37+
<action type="add" dev="rbri">
2238
Dummy impl of PointerEvent#getPersistentDeviceId() returning always 0.
2339
</action>
2440
<action type="update" dev="rbri" issue="#1002">

src/main/java/org/htmlunit/WebClientOptions.java

Lines changed: 97 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@
3030
import org.apache.commons.io.FileUtils;
3131

3232
/**
33-
* Represents options of a {@link WebClient}.
33+
* Configuration options for {@link WebClient} instances.
34+
* This class provides fine-grained control over client behavior including:
35+
* <ul>
36+
* <li>JavaScript and CSS processing</li>
37+
* <li>SSL/TLS configuration and certificates</li>
38+
* <li>HTTP timeouts and proxy settings</li>
39+
* <li>Memory management and temporary file handling</li>
40+
* <li>WebSocket and geolocation support</li>
41+
* </ul>
42+
*
43+
* <p>All options have sensible defaults and can be modified independently.</p>
3444
*
3545
* @author Ahmed Ashour
3646
* @author Marc Guillemot
@@ -143,15 +153,16 @@ public void setRedirectEnabled(final boolean enabled) {
143153
}
144154

145155
/**
146-
* Sets the limit to be used when a page refreshes itself by using a
147-
* http refresh header or meta tag. Set this to -1 to allow endless refresh.
148-
* <p>
149-
* Please have in mind, the {@link NiceRefreshHandler} and the {@link ImmediateRefreshHandler}
150-
* have also some loop protection, that triggers first.
156+
* Sets the redirect limit for page refresh operations using HTTP refresh headers or meta tags.
157+
* This prevents infinite refresh loops by limiting the number of consecutive refreshes allowed.
158+
* Set to -1 to allow unlimited refreshes.
151159
*
152-
* @param pageRefreshLimit the number of refresh loops before throwing an exception
160+
* <p>Note: The {@link NiceRefreshHandler} and {@link ImmediateRefreshHandler}
161+
* have additional loop protection that may trigger before this limit.</p>
162+
*
163+
* @param pageRefreshLimit the maximum number of refresh loops, or -1 for unlimited
153164
*/
154-
public void setRedirectEnabled(final int pageRefreshLimit) {
165+
public void setPageRefreshLimit(final int pageRefreshLimit) {
155166
pageRefreshLimit_ = pageRefreshLimit;
156167
}
157168

@@ -165,12 +176,13 @@ public File getTempFileDirectory() {
165176
}
166177

167178
/**
168-
* Sets the directory to be used for storing the response content in
169-
* a temporary file see {@link #setMaxInMemory(int)}.
170-
* If the given directory does not exist, this creates it.
179+
* Sets the directory to be used for storing response content in temporary files.
180+
* See {@link #setMaxInMemory(int)} for when temporary files are created.
181+
* If the directory doesn't exist, it will be created automatically.
171182
*
172-
* @param tempFileDirectory the directory to be used or null to use the system default
173-
* @throws IOException in case of error
183+
* @param tempFileDirectory the directory to use, or {@code null} for system default
184+
* @throws IOException if directory creation fails
185+
* @throws IllegalArgumentException if the path points to an existing file
174186
*/
175187
public void setTempFileDirectory(final File tempFileDirectory) throws IOException {
176188
if (tempFileDirectory != null) {
@@ -316,6 +328,8 @@ public String[] getSSLClientProtocols() {
316328
* @param sslClientProtocols the protocol versions
317329
* @see javax.net.ssl.SSLSocket#setEnabledProtocols(String[])
318330
* @see #getSSLClientProtocols()
331+
* @see #setSSLClientCipherSuites(String...)
332+
* @see #setUseInsecureSSL(boolean)
319333
*/
320334
public void setSSLClientProtocols(final String... sslClientProtocols) {
321335
sslClientProtocols_ = sslClientProtocols;
@@ -516,7 +530,8 @@ public void setProxyConfig(final ProxyConfig proxyConfig) {
516530
* Gets the timeout value for the {@link WebConnection}.
517531
* The default timeout is 90 seconds.
518532
* @return the timeout value in milliseconds
519-
* @see WebClientOptions#setTimeout(int)
533+
* @see #setTimeout(int)
534+
* @see #setConnectionTimeToLive(long)
520535
*/
521536
public int getTimeout() {
522537
return timeout_;
@@ -544,11 +559,11 @@ public long getConnectionTimeToLive() {
544559
}
545560

546561
/**
547-
* Sets the connTimeToLive of the HttpClient connection pool.
548-
* Use this if you are working with web pages behind a DNS based load balancer.
549-
* Set to -1 (default) for disabling this timeout.
562+
* Sets the connection time-to-live for the HttpClient connection pool.
563+
* This is useful when working with web pages behind DNS-based load balancers
564+
* where IP addresses may change frequently.
550565
*
551-
* @param connectionTimeToLive the value of the timeout in milliseconds
566+
* @param connectionTimeToLive the timeout in milliseconds, or -1 to disable (default)
552567
*/
553568
public void setConnectionTimeToLive(final long connectionTimeToLive) {
554569
connectionTimeToLive_ = connectionTimeToLive;
@@ -618,9 +633,13 @@ private static KeyStore getKeyStore(final InputStream inputStream, final String
618633
}
619634

620635
/**
621-
* Returns the maximum bytes to have in memory, after which the content is saved to a temporary file.
622-
* Default is 500 * 1024.
623-
* @return the maximum bytes in memory
636+
* Returns the maximum bytes stored in memory before content is saved to temporary files.
637+
* When response content exceeds this limit, it will be written to a temporary file
638+
* in the directory specified by {@link #getTempFileDirectory()}.
639+
*
640+
* @return the maximum bytes in memory (default: 500 * 1024)
641+
* @see #setMaxInMemory(int)
642+
* @see #setTempFileDirectory(File)
624643
*/
625644
public int getMaxInMemory() {
626645
return maxInMemory_;
@@ -691,12 +710,10 @@ public InetAddress getLocalAddress() {
691710
}
692711

693712
/**
694-
* Sets the local address to be used for request execution.
695-
* <p>
696-
* On machines with multiple network interfaces, this parameter can be used to select the network interface
697-
* from which the connection originates.
713+
* Sets the local network interface address for outgoing HTTP requests.
714+
* Useful on multi-homed machines to control which network interface is used.
698715
*
699-
* @param localAddress the local address
716+
* @param localAddress the local IP address to bind to, or {@code null} for automatic selection
700717
*/
701718
public void setLocalAddress(final InetAddress localAddress) {
702719
localAddress_ = localAddress;
@@ -720,8 +737,9 @@ public boolean isDownloadImages() {
720737

721738
/**
722739
* Sets the screen width.
740+
* This value is used by JavaScript's screen.width property.
723741
*
724-
* @param screenWidth the screen width
742+
* @param screenWidth the screen width in pixels (must be positive)
725743
*/
726744
public void setScreenWidth(final int screenWidth) {
727745
screenWidth_ = screenWidth;
@@ -755,16 +773,23 @@ public int getScreenHeight() {
755773
}
756774

757775
/**
758-
* @return the Neko Html parser reader buffer size
776+
* Returns the Neko HTML parser reader buffer size.
777+
* This controls the internal buffer size used by the NekoHTML parser
778+
* for reading HTML content. Larger buffers can improve performance
779+
* for large documents but consume more memory.
780+
*
781+
* @return the buffer size in bytes, or -1 for parser default
759782
*/
760783
public int getNekoReaderBufferSize() {
761784
return nekoReaderBufferSize_;
762785
}
763786

764787
/**
765-
* Sets the Neko Html parser reader buffer size.
788+
* Sets the Neko HTML parser reader buffer size.
789+
* A larger buffer size can improve parsing performance for large HTML documents
790+
* but will consume more memory. Set to -1 to use the parser's default buffer size.
766791
*
767-
* @param nekoReaderBufferSize the new value
792+
* @param nekoReaderBufferSize the buffer size in bytes, or -1 for default
768793
*/
769794
public void setNekoReaderBufferSize(final int nekoReaderBufferSize) {
770795
nekoReaderBufferSize_ = nekoReaderBufferSize;
@@ -789,64 +814,82 @@ public boolean isWebSocketEnabled() {
789814
}
790815

791816
/**
792-
* @return the WebSocket maxTextMessageSize
817+
* Returns the maximum size in bytes for WebSocket text messages.
818+
* Set to -1 to use the default.
819+
*
820+
* @return the maximum text message size in bytes, or -1 for default
793821
*/
794822
public int getWebSocketMaxTextMessageSize() {
795823
return webSocketMaxTextMessageSize_;
796824
}
797825

798826
/**
799-
* Sets the WebSocket maxTextMessageSize.
827+
* Sets the maximum size in bytes for WebSocket text messages.
828+
* This limit applies to individual text frames received by the WebSocket.
800829
*
801-
* @param webSocketMaxTextMessageSize the new value
830+
* @param webSocketMaxTextMessageSize the maximum size in bytes, or -1 for default
802831
*/
803832
public void setWebSocketMaxTextMessageSize(final int webSocketMaxTextMessageSize) {
804833
webSocketMaxTextMessageSize_ = webSocketMaxTextMessageSize;
805834
}
806835

807836
/**
808-
* @return the WebSocket maxTextMessageBufferSize
837+
* Returns the maximum buffer size in bytes for assembling WebSocket text messages.
838+
* Set to -1 to use the default.
839+
*
840+
* @return the maximum text message buffer size in bytes, or -1 for default
809841
*/
810842
public int getWebSocketMaxTextMessageBufferSize() {
811843
return webSocketMaxTextMessageBufferSize_;
812844
}
813845

814846
/**
815-
* Sets the WebSocket maxTextMessageBufferSize.
847+
* Sets the maximum buffer size in bytes for assembling WebSocket text messages.
848+
* This controls the memory used when reconstructing fragmented text messages.
849+
* The buffer size should typically be larger than the maximum message size to
850+
* accommodate message assembly overhead.
816851
*
817-
* @param webSocketMaxTextMessageBufferSize the new value
852+
* @param webSocketMaxTextMessageBufferSize the maximum buffer size in bytes, or -1 for default
818853
*/
819854
public void setWebSocketMaxTextMessageBufferSize(final int webSocketMaxTextMessageBufferSize) {
820855
webSocketMaxTextMessageBufferSize_ = webSocketMaxTextMessageBufferSize;
821856
}
822857

823858
/**
824-
* @return the WebSocket maxTextMessageSize
859+
* Returns the maximum size in bytes for WebSocket binary messages.
860+
* Set to -1 to use the default.
861+
*
862+
* @return the maximum binary message size in bytes, or -1 for default
825863
*/
826864
public int getWebSocketMaxBinaryMessageSize() {
827865
return webSocketMaxBinaryMessageSize_;
828866
}
829867

830868
/**
831-
* Sets the WebSocket maxBinaryMessageSize.
869+
* Sets the maximum size in bytes for WebSocket binary messages.
870+
* This limit applies to individual binary frames received by the WebSocket.
832871
*
833-
* @param webSocketMaxBinaryMessageSize the new value
872+
* @param webSocketMaxBinaryMessageSize the maximum size in bytes, or -1 for default
834873
*/
835874
public void setWebSocketMaxBinaryMessageSize(final int webSocketMaxBinaryMessageSize) {
836875
webSocketMaxBinaryMessageSize_ = webSocketMaxBinaryMessageSize;
837876
}
838877

839878
/**
840-
* @return the WebSocket maxBinaryMessageBufferSize
879+
* Returns the maximum buffer size in bytes for assembling WebSocket binary messages.
880+
* Set to -1 to use the container default.
881+
*
882+
* @return the maximum binary message buffer size in bytes, or -1 for default
841883
*/
842884
public int getWebSocketMaxBinaryMessageBufferSize() {
843885
return webSocketMaxBinaryMessageBufferSize_;
844886
}
845887

846888
/**
847-
* Sets the WebSocket maxBinaryMessageBufferSize.
889+
* Sets the maximum buffer size in bytes for assembling WebSocket binary messages.
890+
* This controls the memory used when reconstructing fragmented binary messages.
848891
*
849-
* @param webSocketMaxBinaryMessageBufferSize the new value
892+
* @param webSocketMaxBinaryMessageBufferSize the maximum buffer size in bytes, or -1 for default
850893
*/
851894
public void setWebSocketMaxBinaryMessageBufferSize(final int webSocketMaxBinaryMessageBufferSize) {
852895
webSocketMaxBinaryMessageBufferSize_ = webSocketMaxBinaryMessageBufferSize;
@@ -913,13 +956,13 @@ public static class Geolocation implements Serializable {
913956
/**
914957
* Ctor.
915958
*
916-
* @param accuracy the accuracy
917-
* @param latitude the latitude
918-
* @param longitude the longitude
919-
* @param altitude the altitude or null
920-
* @param altitudeAccuracy the altitudeAccuracy or null
921-
* @param heading the heading or null
922-
* @param speed the speed or null
959+
* @param latitude the latitude coordinate in decimal degrees
960+
* @param longitude the longitude coordinate in decimal degrees
961+
* @param accuracy the accuracy of the position in meters
962+
* @param altitude the altitude in meters above sea level, or null if unavailable
963+
* @param altitudeAccuracy the accuracy of the altitude in meters, or null if unavailable
964+
* @param heading the direction of travel in degrees (0-359), or null if unavailable
965+
* @param speed the current speed in meters per second, or null if unavailable
923966
*/
924967
public Geolocation(
925968
final double latitude,
@@ -992,7 +1035,11 @@ public Double getSpeed() {
9921035
* If set to {@code true}, the client will accept XMLHttpRequests to URL's
9931036
* using the 'file' protocol. Allowing this introduces security problems and is
9941037
* therefore not allowed by current browsers. But some browsers have special settings
995-
* to open this door; therefore we have this option.
1038+
* to open this door; therefore we have this option also.
1039+
*
1040+
* <p><b>Security Warning:</b> Enabling this feature may expose local files
1041+
* to web content, which can be a serious security risk.</p>
1042+
*
9961043
* @param fileProtocolForXMLHttpRequestsAllowed whether or not allow (local) file access
9971044
*/
9981045
public void setFileProtocolForXMLHttpRequestsAllowed(final boolean fileProtocolForXMLHttpRequestsAllowed) {

0 commit comments

Comments
 (0)