@@ -601,7 +601,7 @@ public void onException(TcpChannel channel, Exception e) {
601601 "cancelled key exception caught on transport layer [{}], disconnecting from relevant node" , channel ), e );
602602 // close the channel as safe measure, which will cause a node to be disconnected if relevant
603603 CloseableChannel .closeChannel (channel );
604- } else if (e instanceof TcpTransport . HttpOnTransportException ) {
604+ } else if (e instanceof HttpRequestOnTransportException ) {
605605 // in case we are able to return data, serialize the exception content and sent it back to the client
606606 if (channel .isOpen ()) {
607607 BytesArray message = new BytesArray (e .getMessage ().getBytes (StandardCharsets .UTF_8 ));
@@ -674,7 +674,7 @@ public void inboundMessage(TcpChannel channel, BytesReference message) {
674674 * @param bytesReference the bytes available to consume
675675 * @return the number of bytes consumed
676676 * @throws StreamCorruptedException if the message header format is not recognized
677- * @throws TcpTransport.HttpOnTransportException if the message header appears to be an HTTP message
677+ * @throws HttpRequestOnTransportException if the message header appears to be an HTTP message
678678 * @throws IllegalArgumentException if the message length is greater that the maximum allowed frame size.
679679 * This is dependent on the available memory.
680680 */
@@ -696,7 +696,7 @@ public int consumeNetworkReads(TcpChannel channel, BytesReference bytesReference
696696 * @param networkBytes the will be read
697697 * @return the message decoded
698698 * @throws StreamCorruptedException if the message header format is not recognized
699- * @throws TcpTransport.HttpOnTransportException if the message header appears to be an HTTP message
699+ * @throws HttpRequestOnTransportException if the message header appears to be an HTTP message
700700 * @throws IllegalArgumentException if the message length is greater that the maximum allowed frame size.
701701 * This is dependent on the available memory.
702702 */
@@ -723,7 +723,7 @@ static BytesReference decodeFrame(BytesReference networkBytes) throws IOExceptio
723723 * @param networkBytes the will be read
724724 * @return the length of the message
725725 * @throws StreamCorruptedException if the message header format is not recognized
726- * @throws TcpTransport.HttpOnTransportException if the message header appears to be an HTTP message
726+ * @throws HttpRequestOnTransportException if the message header appears to be an HTTP message
727727 * @throws IllegalArgumentException if the message length is greater that the maximum allowed frame size.
728728 * This is dependent on the available memory.
729729 */
@@ -737,8 +737,13 @@ public static int readMessageLength(BytesReference networkBytes) throws IOExcept
737737
738738 private static int readHeaderBuffer (BytesReference headerBuffer ) throws IOException {
739739 if (headerBuffer .get (0 ) != 'E' || headerBuffer .get (1 ) != 'S' ) {
740- if (appearsToBeHTTP (headerBuffer )) {
741- throw new TcpTransport .HttpOnTransportException ("This is not an HTTP port" );
740+ if (appearsToBeHTTPRequest (headerBuffer )) {
741+ throw new HttpRequestOnTransportException ("This is not an HTTP port" );
742+ }
743+
744+ if (appearsToBeHTTPResponse (headerBuffer )) {
745+ throw new StreamCorruptedException ("received HTTP response on transport port, ensure that transport port (not " +
746+ "HTTP port) of a remote node is specified in the configuration" );
742747 }
743748
744749 String firstBytes = "("
@@ -772,7 +777,7 @@ private static int readHeaderBuffer(BytesReference headerBuffer) throws IOExcept
772777 return messageLength ;
773778 }
774779
775- private static boolean appearsToBeHTTP (BytesReference headerBuffer ) {
780+ private static boolean appearsToBeHTTPRequest (BytesReference headerBuffer ) {
776781 return bufferStartsWith (headerBuffer , "GET" ) ||
777782 bufferStartsWith (headerBuffer , "POST" ) ||
778783 bufferStartsWith (headerBuffer , "PUT" ) ||
@@ -784,6 +789,10 @@ private static boolean appearsToBeHTTP(BytesReference headerBuffer) {
784789 bufferStartsWith (headerBuffer , "TRACE" );
785790 }
786791
792+ private static boolean appearsToBeHTTPResponse (BytesReference headerBuffer ) {
793+ return bufferStartsWith (headerBuffer , "HTTP" );
794+ }
795+
787796 private static boolean appearsToBeTLS (BytesReference headerBuffer ) {
788797 return headerBuffer .get (0 ) == 0x16 && headerBuffer .get (1 ) == 0x03 ;
789798 }
@@ -802,9 +811,9 @@ private static boolean bufferStartsWith(BytesReference buffer, String method) {
802811 * A helper exception to mark an incoming connection as potentially being HTTP
803812 * so an appropriate error code can be returned
804813 */
805- public static class HttpOnTransportException extends ElasticsearchException {
814+ public static class HttpRequestOnTransportException extends ElasticsearchException {
806815
807- private HttpOnTransportException (String msg ) {
816+ private HttpRequestOnTransportException (String msg ) {
808817 super (msg );
809818 }
810819
@@ -813,7 +822,7 @@ public RestStatus status() {
813822 return RestStatus .BAD_REQUEST ;
814823 }
815824
816- public HttpOnTransportException (StreamInput in ) throws IOException {
825+ public HttpRequestOnTransportException (StreamInput in ) throws IOException {
817826 super (in );
818827 }
819828 }
0 commit comments