Skip to content

Commit 05b9f0c

Browse files
Copilotchrjohn
andcommitted
Extract Proxy-Authorization header name as constant
Co-authored-by: chrjohn <6644028+chrjohn@users.noreply.github.com>
1 parent 0d429ce commit 05b9f0c

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

quickfixj-core/src/main/java/quickfix/mina/ProtocolFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public class ProtocolFactory {
5757

5858
public final static int SOCKET = 0;
5959
public final static int VM_PIPE = 1;
60+
61+
public final static String PROXY_AUTHORIZATION_HEADER = "Proxy-Authorization";
6062

6163
public static String getTypeString(int type) {
6264
switch (type) {
@@ -176,7 +178,7 @@ private static ProxyRequest createHttpProxyRequest(InetSocketAddress address,
176178
Map<String, List<String>> headers = new HashMap<>();
177179
String credentials = proxyUser + ":" + proxyPassword;
178180
String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes(StandardCharsets.UTF_8));
179-
headers.put("Proxy-Authorization", Collections.singletonList("Basic " + encodedCredentials));
181+
headers.put(PROXY_AUTHORIZATION_HEADER, Collections.singletonList("Basic " + encodedCredentials));
180182
req.setHeaders(headers);
181183
}
182184

quickfixj-core/src/test/java/quickfix/mina/ProtocolFactoryTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static org.junit.Assert.assertNotNull;
3838
import static org.junit.Assert.assertNull;
3939
import static org.junit.Assert.assertTrue;
40+
import static quickfix.mina.ProtocolFactory.PROXY_AUTHORIZATION_HEADER;
4041

4142
public class ProtocolFactoryTest {
4243

@@ -69,9 +70,9 @@ public void shouldSetBasicAuthorizationHeaderForHttpProxy() throws ConfigError {
6970

7071
Map<String, List<String>> headers = request.getHeaders();
7172
assertNotNull("Headers should not be null", headers);
72-
assertTrue("Headers should contain Proxy-Authorization", headers.containsKey("Proxy-Authorization"));
73+
assertTrue("Headers should contain Proxy-Authorization", headers.containsKey(PROXY_AUTHORIZATION_HEADER));
7374

74-
List<String> authHeaders = headers.get("Proxy-Authorization");
75+
List<String> authHeaders = headers.get(PROXY_AUTHORIZATION_HEADER);
7576
assertNotNull("Proxy-Authorization header should not be null", authHeaders);
7677
assertEquals("Should have exactly one Proxy-Authorization header", 1, authHeaders.size());
7778

@@ -100,7 +101,7 @@ public void shouldNotSetAuthorizationHeaderForNTLMAuthentication() throws Config
100101
Map<String, List<String>> headers = request.getHeaders();
101102
// NTLM requires multi-step handshake, so Proxy-Authorization header should not be set upfront
102103
assertTrue("Headers should be null or not contain Proxy-Authorization for NTLM",
103-
headers == null || !headers.containsKey("Proxy-Authorization"));
104+
headers == null || !headers.containsKey(PROXY_AUTHORIZATION_HEADER));
104105

105106
// Verify NTLM properties are set correctly for the MINA proxy handler to use
106107
Map<String, String> props = request.getProperties();
@@ -124,6 +125,6 @@ public void shouldNotSetAuthorizationHeaderWhenCredentialsNotProvided() throws C
124125
Map<String, List<String>> headers = request.getHeaders();
125126
// Headers should either be null or not contain Proxy-Authorization
126127
assertTrue("Headers should be null or empty when no credentials provided",
127-
headers == null || !headers.containsKey("Proxy-Authorization"));
128+
headers == null || !headers.containsKey(PROXY_AUTHORIZATION_HEADER));
128129
}
129130
}

0 commit comments

Comments
 (0)