-
Notifications
You must be signed in to change notification settings - Fork 43
DOCSP-31694: SOCKS5 proxy support #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
579b162
5b87624
ecd8f12
8318bc1
85f082d
5201d05
0c5fc6c
efdf2ab
924b699
5bf94ff
3889dbe
33845ea
3f97f98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
.. _java-connect-socks: | ||
|
||
========================================== | ||
Connect to MongoDB by Using a SOCKS5 Proxy | ||
========================================== | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 2 | ||
:class: singlecol | ||
|
||
Overview | ||
-------- | ||
|
||
In this guide, you can learn how to connect to MongoDB by using a SOCKS5 proxy. | ||
SOCKS5 is a standardized protocol for communicating with network services | ||
through a proxy server. | ||
|
||
.. tip:: | ||
|
||
To learn more about the SOCKS5 protocol, see the Uncyclopedia entry on | ||
:wikipedia:`SOCKS <w/index.php?title=SOCKS&oldid=1160087146>`. | ||
|
||
.. _socks-proxy-settings: | ||
|
||
SOCKS5 Proxy Settings | ||
--------------------- | ||
|
||
The proxy settings specify the SOCKS5 proxy server address and your | ||
authentication credentials. You can specify your settings in an instance of | ||
``MongoClientSettings`` or in your connection URI. | ||
|
||
The following table describes the SOCKS5 client options: | ||
|
||
.. list-table:: | ||
:header-rows: 1 | ||
:widths: 15 20 65 | ||
|
||
* - Name | ||
- Accepted Values | ||
- Description | ||
|
||
* - **proxyHost** | ||
- String | ||
- *Required*. Specifies the SOCKS5 proxy IPv4 address, IPv6 address, or hostname. | ||
|
||
* - **proxyPort** | ||
- non-negative Integer | ||
- Specifies the TCP port number of the SOCKS5 proxy server. If you | ||
set the ``proxyHost`` option, the value of this option defaults | ||
to ``1080``. | ||
|
||
* - **proxyUsername** | ||
- String | ||
- Specifies the username for authentication to the SOCKS5 | ||
proxy server. The driver ignores ``null`` and empty string values for | ||
this setting. | ||
|
||
* - **proxyPassword** | ||
- String | ||
- Specifies the password for authentication to the SOCKS5 | ||
proxy server. The driver ignores ``null`` and empty string values | ||
for this setting. | ||
|
||
|
||
Examples | ||
-------- | ||
|
||
The following examples show how to instantiate a ``MongoClient`` that connects | ||
to MongoDB by using a SOCKS5 proxy by using a ``MongoClientSettings`` instance | ||
or a connection string. These examples use the placeholder values described in | ||
jordan-smith721 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
the :ref:`socks-proxy-settings` section. Replace the placeholders with your | ||
proxy settings. | ||
|
||
Specify Proxy Settings in the MongoClientSettings | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The following code example shows how to specify your SOCKS5 proxy settings by | ||
using the ``MongoClientSettings`` builder: | ||
|
||
.. code-block:: java | ||
:emphasize-lines: 4-11 | ||
|
||
MongoClient mongoClient = MongoClients.create( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this code snippet starts off indented more than it needs to be. Since the third line is pretty long can the extra indentation be removed to show as much as possible without scrolling? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||
MongoClientSettings.builder() | ||
.applyConnectionString(new ConnectionString("mongodb+srv://myDatabaseUser:[email protected]/")) | ||
.applyToSocketSettings(builder -> | ||
builder.applyToProxySettings(proxyBuilder -> | ||
proxyBuilder | ||
.host("<proxyHost>") | ||
.port(<proxyPort>) | ||
.username("<proxyUsername>") | ||
.password("<proxyPassword>") | ||
) | ||
).build()); | ||
|
||
Specify Proxy Settings in the Connection String | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
This following code example shows how to specify your SOCKS5 proxy settings in | ||
jordan-smith721 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
your connection string: | ||
|
||
.. code-block:: java | ||
:emphasize-lines: 2-5 | ||
|
||
String connectionString = "mongodb+srv://myDatabaseUser:[email protected]/" + | ||
"?proxyHost=<proxyHost>" + | ||
"&proxyPort=<proxyPort>" + | ||
"&proxyUsername=<proxyUsername>" + | ||
"&proxyPassword=<proxyPassword>"; | ||
|
||
MongoClient mongoClient = MongoClients.create(connectionString); | ||
|
||
API Documentation | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
To learn more about the methods and types discussed in this guide, see the | ||
following API documentation: | ||
|
||
- `MongoClientSettings.Builder <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html>`__ | ||
- `SocketSettings.Builder <{+api+}/apidocs/mongodb-driver-core/com/mongodb/connection/SocketSettings.Builder.html>`__ | ||
- `MongoClients.create() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoClients.html#create(com.mongodb.MongoClientSettings)>`__ | ||
|
||
.. TODO | ||
- provide the link for the proxysettings builder once the API docs are generated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be replaced by the ProxySettings Builder API docs link once v4.11 is published. |
Uh oh!
There was an error while loading. Please reload this page.