@Test public void testRequireHeaderNegativeCases() throws Exception { assertFalse(validator.requireHeader(null, null)); final HttpRequestMessage request = makeHandshakeRequest(); assertFalse(validator.requireHeader(request, null)); assertFalse(validator.requireHeader(null, "HeaderName")); assertFalse(validator.requireHeader(null, null, null)); assertFalse(validator.requireHeader(null, "Connection", "Upgrade")); assertFalse(validator.requireHeader(request, null, null)); assertFalse(validator.requireHeader(request, "Connection", null)); assertFalse(validator.requireHeader(request, null, "Upgrade")); assertTrue(validator.requireHeader(request, "Connection", "Upgrade")); }
public boolean requireHeader(HttpRequestMessage request, String name) { if ( request == null || name == null ) { return false; } List<String> headers = request.getHeaderValues(name, false); if ( headers != null ) { boolean found = false; for(String header: headers) { if ( header != null && header.trim().length() > 0) { found = true; } } return found; } return false; }
WsHandshakeValidator { public boolean requireHeader(HttpRequestMessage request, String name) { if ( request == null || name == null ) { return false; } List<String> headers = request.getHeaderValues(name, false); if ( headers != null ) { boolean found = false; for(String header: headers) { if ( header != null && header.trim().length() > 0) { found = true; } } return found; } return false; } }
WsHandshakeValidator { public boolean requireHeader(HttpRequestMessage request, String name) { if ( request == null || name == null ) { return false; } List<String> headers = request.getHeaderValues(name, false); if ( headers != null ) { boolean found = false; for(String header: headers) { if ( header != null && header.trim().length() > 0) { found = true; } } return found; } return false; }  }
WsHandshakeValidator { public boolean requireHeader(HttpRequestMessage request, String name) { if ( request == null || name == null ) { return false; } List<String> headers = request.getHeaderValues(name, false); if ( headers != null ) { boolean found = false; for(String header: headers) { if ( header != null && header.trim().length() > 0) { found = true; } } return found; } return false; }  boolean validate(HttpRequestMessage request); boolean validate(HttpRequestMessage request, boolean isPostMethodAllowed); static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest); boolean requireHeader(HttpRequestMessage request, String name); boolean requireHeader(HttpRequestMessage request, String name, String value); boolean isInitialized(); synchronized void init(); }
WsHandshakeValidator { public boolean requireHeader(HttpRequestMessage request, String name) { if ( request == null || name == null ) { return false; } List<String> headers = request.getHeaderValues(name, false); if ( headers != null ) { boolean found = false; for(String header: headers) { if ( header != null && header.trim().length() > 0) { found = true; } } return found; } return false; }  boolean validate(HttpRequestMessage request); boolean validate(HttpRequestMessage request, boolean isPostMethodAllowed); static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest); boolean requireHeader(HttpRequestMessage request, String name); boolean requireHeader(HttpRequestMessage request, String name, String value); boolean isInitialized(); synchronized void init(); static final String SEC_WEB_SOCKET_KEY; static final String SEC_WEB_SOCKET_VERSION; static final String SEC_WEB_SOCKET_KEY1; static final String SEC_WEB_SOCKET_KEY2; static Map<WebSocketWireProtocol, WsHandshakeValidator> handshakeValidatorsByWireProtocolVersion; }