2525
2626import java .io .IOException ;
2727import java .net .URL ;
28+ import java .util .Collections ;
29+ import java .util .HashMap ;
2830import java .util .Map ;
2931import org .openqa .selenium .NoSuchSessionException ;
3032import org .openqa .selenium .SessionNotCreatedException ;
@@ -46,7 +48,7 @@ public class HttpCommandExecutor implements CommandExecutor, NeedsLocalLogs {
4648 private final URL remoteServer ;
4749 public final HttpClient client ;
4850 private final HttpClient .Factory httpClientFactory ;
49- protected final Map <String , CommandInfo > additionalCommands ;
51+ private final Map <String , CommandInfo > additionalCommands ;
5052 protected CommandCodec <HttpRequest > commandCodec ;
5153 protected ResponseCodec <HttpResponse > responseCodec ;
5254
@@ -109,11 +111,34 @@ public HttpCommandExecutor(
109111 ClientConfig config ,
110112 HttpClient .Factory httpClientFactory ) {
111113 remoteServer = Require .nonNull ("HTTP client configuration" , config ).baseUrl ();
112- this .additionalCommands = Require .nonNull ("Additional commands" , additionalCommands );
114+ this .additionalCommands =
115+ new HashMap <>(Require .nonNull ("Additional commands" , additionalCommands ));
113116 this .httpClientFactory = Require .nonNull ("HTTP client factory" , httpClientFactory );
114117 this .client = this .httpClientFactory .createClient (config );
115118 }
116119
120+ /**
121+ * Returns an immutable view of the additional commands.
122+ *
123+ * @return an unmodifiable map of additional commands.
124+ */
125+ public Map <String , CommandInfo > getAdditionalCommands () {
126+ return Collections .unmodifiableMap (additionalCommands );
127+ }
128+
129+ /**
130+ * Adds or updates additional commands. This method is protected to allow subclasses to define
131+ * their commands.
132+ *
133+ * @param commandName the name of the command to add or update.
134+ * @param info the CommandInfo for the command.
135+ */
136+ protected void addAdditionalCommand (String commandName , CommandInfo info ) {
137+ Require .nonNull ("Command name" , commandName );
138+ Require .nonNull ("Command info" , info );
139+ this .additionalCommands .put (commandName , info );
140+ }
141+
117142 /**
118143 * It may be useful to extend the commands understood by this {@code HttpCommandExecutor} at run
119144 * time, and this can be achieved via this method. Note, this is protected, and expected usage is
0 commit comments