-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) Microsoft. All rights reserved. | ||
* Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
*/ | ||
|
||
package com.microsoft.azure.proton.transport.proxy; | ||
|
||
import java.util.Map; | ||
|
||
import org.apache.qpid.proton.engine.Transport; | ||
|
||
public interface Proxy { | ||
enum ProxyState { | ||
PN_PROXY_NOT_STARTED, | ||
PN_PROXY_CONNECTING, | ||
PN_PROXY_CONNECTED, | ||
PN_PROXY_FAILED | ||
} | ||
|
||
void configure( | ||
String host, | ||
Map<String, String> headers, | ||
ProxyHandler proxyHandler, | ||
Transport underlyingTransport); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) Microsoft. All rights reserved. | ||
* Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
*/ | ||
|
||
package com.microsoft.azure.proton.transport.proxy; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.Map; | ||
|
||
public interface ProxyHandler { | ||
|
||
class ProxyResponseResult { | ||
private Boolean isSuccess; | ||
private String error; | ||
|
||
public ProxyResponseResult(final Boolean isSuccess, final String error) { | ||
this.isSuccess = isSuccess; | ||
this.error = error; | ||
} | ||
|
||
public Boolean getIsSuccess() { | ||
return isSuccess; | ||
} | ||
|
||
public String getError() { | ||
return error; | ||
} | ||
} | ||
|
||
String createProxyRequest(String hostName, Map<String, String> additionalHeaders); | ||
|
||
ProxyResponseResult validateProxyResponse(ByteBuffer buffer); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) Microsoft. All rights reserved. | ||
* Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
*/ | ||
|
||
package com.microsoft.azure.proton.transport.proxy.impl; | ||
|
||
import com.microsoft.azure.proton.transport.proxy.ProxyHandler; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Map; | ||
import java.util.Scanner; | ||
|
||
public class ProxyHandlerImpl implements ProxyHandler { | ||
|
||
@Override | ||
public String createProxyRequest(String hostName, Map<String, String> additionalHeaders) { | ||
final String endOfLine = "\r\n"; | ||
final StringBuilder connectRequestBuilder = new StringBuilder(); | ||
connectRequestBuilder.append( | ||
String.format( | ||
"CONNECT %1$s HTTP/1.1%2$sHost: %1$s%2$sConnection: Keep-Alive%2$s", | ||
hostName, | ||
endOfLine)); | ||
if (additionalHeaders != null) { | ||
for (Map.Entry<String, String> entry: additionalHeaders.entrySet()) { | ||
connectRequestBuilder.append(entry.getKey()); | ||
connectRequestBuilder.append(": "); | ||
connectRequestBuilder.append(entry.getValue()); | ||
connectRequestBuilder.append(endOfLine); | ||
} | ||
} | ||
connectRequestBuilder.append(endOfLine); | ||
return connectRequestBuilder.toString(); | ||
} | ||
|
||
@Override | ||
public ProxyResponseResult validateProxyResponse(ByteBuffer buffer) { | ||
int size = buffer.remaining(); | ||
String response = null; | ||
|
||
if (size > 0) { | ||
byte[] responseBytes = new byte[buffer.remaining()]; | ||
buffer.get(responseBytes); | ||
response = new String(responseBytes, StandardCharsets.UTF_8); | ||
final Scanner responseScanner = new Scanner(response); | ||
if (responseScanner.hasNextLine()) { | ||
final String firstLine = responseScanner.nextLine(); | ||
if (firstLine.toLowerCase().contains("http/1.1") | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
JamesBirdsall
Contributor
|
||
&& firstLine.contains("200") | ||
&& firstLine.toLowerCase().contains("connection established")) { | ||
return new ProxyResponseResult(true, null); | ||
} | ||
} | ||
} | ||
|
||
return new ProxyResponseResult(false, response); | ||
} | ||
} |
Is it possible to consider http/1.0 as a valid request as well? Because as far as I can see it would work with that version aswell, so in my opinion this restriction unnecessarily limits the use of the library.