1313using Tests . Core . Extensions ;
1414using Tests . Domain ;
1515using Tests . Framework ;
16+ #if DOTNETCORE
17+ using System . Net . Http ;
18+ using System . Net . Http . Headers ;
19+ #endif
1620
1721namespace Tests . ClientConcepts . Connection
1822{
@@ -112,14 +116,60 @@ public void InMemoryConnectionOverloadedCtor()
112116 }
113117
114118 /**
115- /**==== Customize HttpConnection
116- *
117- * For a lot of use cases subclassing HttpConnection is a great way to customize the http connection for your needs.
118- * E.g if you want to authenticate with Kerberos, creating a custom HttpConnection as followed allows you to set the right HTTP headers.
119- *
120- *
121- * TIP use something like https://www.nuget.org/packages/Kerberos.NET/ to fill in the actual blanks of this implementation
119+ * ==== Changing HttpConnection
120+ *
121+ * There may be a need to change how the default `HttpConnection` works, for example, to add an X509 certificate
122+ * to the request, change the maximum number of connections allowed to an endpoint, etc.
123+ *
124+ * By deriving from `HttpConnection`, it is possible to change the behaviour of the connection. The following
125+ * provides some examples
126+ *
127+ *
128+ * [[servicepoint-behaviour]]
129+ * ===== ServicePoint behaviour
130+ *
131+ * If you are running on the Desktop CLR you can override specific properties for the current `ServicePoint` easily
132+ * by overriding `AlterServicePoint` on an `IConnection` implementation deriving from `HttpConnection`
133+ */
134+ #if ! DOTNETCORE
135+ public class MyCustomHttpConnection : HttpConnection
136+ {
137+ protected override HttpRequestMessage CreateRequestMessage ( RequestData requestData )
138+ {
139+ var message = base . CreateRequestMessage ( requestData ) ;
140+ var header = string . Empty ;
141+ message . Headers . Authorization = new AuthenticationHeaderValue ( "Negotiate" , header ) ;
142+ return message ;
143+ }
144+ }
145+
146+
147+ /**
148+ * As before, a new instance of the custom connection is passed to `ConnectionSettings` in order to
149+ * use
150+ */
151+ public void UseX509CertificateHttpConnection ( )
152+ {
153+ var connection = new X509CertificateHttpConnection ( ) ;
154+ var connectionPool = new SingleNodeConnectionPool ( new Uri ( "http://localhost:9200" ) ) ;
155+ var settings = new ConnectionSettings ( connectionPool , connection ) ;
156+ var client = new ElasticClient ( settings ) ;
157+ }
158+ /**
159+ * See <<working-with-certificates, Working with certificates>> for further details.
122160 */
161+ #endif
162+ #if DOTNETCORE
163+ /*
164+ * [[kerberos-authentication]]
165+ * ===== Kerberos Authentication
166+ *
167+ * For a lot of use cases subclassing HttpConnection is a great way to customize the http connection for your needs.
168+ * E.g if you want to authenticate with Kerberos, creating a custom HttpConnection as followed allows you to set the right HTTP headers.
169+ *
170+ *
171+ * TIP use something like https://www.nuget.org/packages/Kerberos.NET/ to fill in the actual blanks of this implementation
172+ */
123173 public class KerberosConnection : HttpConnection
124174 {
125175 protected override HttpRequestMessage CreateRequestMessage ( RequestData requestData )
@@ -130,6 +180,8 @@ protected override HttpRequestMessage CreateRequestMessage(RequestData requestDa
130180 return message ;
131181 }
132182 }
183+ #endif
184+
133185
134186
135187 }
0 commit comments