You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2020/12/14 12:54:43 UTC
[camel] 03/03: TEMP BACK OUT: Fiddler workaround
This is an automated email from the ASF dual-hosted git repository.
zregvart pushed a commit to branch issue/CAMEL-12871
in repository https://gitbox.apache.org/repos/asf/camel.git
commit ea67b383303ba381e85baf26f3f421e457cd0143
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Mon Dec 14 13:52:20 2020 +0100
TEMP BACK OUT: Fiddler workaround
This allows proxying HTTPS via HTTP proxy tunneling (`CONNECT`) with
Fiddler. Fiddler is sending `Connection: close` which closes the tunnel
and abruptly terminates the proxy tunnel connection. This removes the
`Connection: close` header in that case.
This change needs to be backed out, and not merged to mainline.
---
.../component/salesforce/SalesforceHttpClient.java | 3 +-
.../SalesforceHttpClientTransportOverHTTP.java | 77 ++++++++++++++++++++++
2 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClient.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClient.java
index 0fce4bb..293d4c2 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClient.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClient.java
@@ -30,7 +30,6 @@ import org.eclipse.jetty.client.HttpConversation;
import org.eclipse.jetty.client.HttpRequest;
import org.eclipse.jetty.client.ProtocolHandler;
import org.eclipse.jetty.client.api.Request;
-import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import static java.util.Optional.ofNullable;
@@ -64,7 +63,7 @@ public class SalesforceHttpClient extends HttpClient {
}
public SalesforceHttpClient(HttpClientTransport transport, SslContextFactory sslContextFactory) {
- super(ofNullable(transport).orElse(new HttpClientTransportOverHTTP()), sslContextFactory);
+ super(ofNullable(transport).orElse(new SalesforceHttpClientTransportOverHTTP()), sslContextFactory);
// Jetty 9.3, as opposed to 9.2 the way to add ProtocolHandler to
// HttpClient changed in 9.2 HttpClient::getProtocolHandlers returned
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClientTransportOverHTTP.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClientTransportOverHTTP.java
new file mode 100644
index 0000000..f3a4456
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClientTransportOverHTTP.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.salesforce;
+
+import org.eclipse.jetty.client.HttpDestination;
+import org.eclipse.jetty.client.HttpExchange;
+import org.eclipse.jetty.client.HttpRequest;
+import org.eclipse.jetty.client.api.Connection;
+import org.eclipse.jetty.client.api.Response;
+import org.eclipse.jetty.client.api.Result;
+import org.eclipse.jetty.client.http.HttpChannelOverHTTP;
+import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP;
+import org.eclipse.jetty.client.http.HttpConnectionOverHTTP;
+import org.eclipse.jetty.http.HttpFields;
+import org.eclipse.jetty.http.HttpHeader;
+import org.eclipse.jetty.http.HttpMethod;
+import org.eclipse.jetty.http.HttpVersion;
+import org.eclipse.jetty.io.EndPoint;
+import org.eclipse.jetty.util.Promise;
+
+/**
+ * A workaround for Fiddler sending <code>Connection: close</code> on HTTPS proxy tunneling via CONNECT.
+ */
+public class SalesforceHttpClientTransportOverHTTP extends HttpClientTransportOverHTTP {
+
+ public class SalesforceHttpChannelOverHTTP extends HttpChannelOverHTTP {
+
+ public SalesforceHttpChannelOverHTTP(final HttpConnectionOverHTTP connection) {
+ super(connection);
+ }
+
+ @Override
+ public void exchangeTerminated(final HttpExchange exchange, final Result result) {
+ final Response response = result.getResponse();
+ final HttpRequest request = exchange.getRequest();
+
+ if (response != null && response.getVersion() != null && response.getVersion().compareTo(HttpVersion.HTTP_1_1) >= 0
+ && request != null && HttpMethod.CONNECT.is(request.getMethod())) {
+ final HttpFields headers = response.getHeaders();
+ headers.remove(HttpHeader.CONNECTION);
+ }
+
+ super.exchangeTerminated(exchange, result);
+ }
+ }
+
+ public class SalesforceHttpConnectionOverHTTP extends HttpConnectionOverHTTP {
+
+ public SalesforceHttpConnectionOverHTTP(final EndPoint endPoint, final HttpDestination destination, final Promise<Connection> promise) {
+ super(endPoint, destination, promise);
+ }
+
+ @Override
+ protected HttpChannelOverHTTP newHttpChannel() {
+ return new SalesforceHttpChannelOverHTTP(this);
+ }
+ }
+
+ @Override
+ protected HttpConnectionOverHTTP newHttpConnection(final EndPoint endPoint, final HttpDestination destination, final Promise<Connection> promise) {
+ return new SalesforceHttpConnectionOverHTTP(endPoint, destination, promise);
+ }
+}