From 3491181c63c4e4454f9dc725312a36b1a6a736e4 Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Fri, 14 Jan 2022 10:40:51 -0500 Subject: [PATCH] UNDERTOW-2017: HttpRequestConduit state is correctly maintained Previously, small buffers that required multiple events to write would not save the correct header state, resulting in NPEs and requests which failed to include all headers. This PR removes the duplicated state between the method body and HttpRequestConduit in favor of exclusively using HttpRequestConduit fields. This way the behavior across state changes is unlikely to be impacted at all. Hotspot isn't able to optimize field access quite as well as local method scoped variables, however this isn't likely to have an impact in practice, and it's more important to send all headers with every request. --- .../client/http/HttpRequestConduit.java | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/core/src/main/java/io/undertow/client/http/HttpRequestConduit.java b/core/src/main/java/io/undertow/client/http/HttpRequestConduit.java index b90e0b46a7..9e8ce206e1 100644 --- a/core/src/main/java/io/undertow/client/http/HttpRequestConduit.java +++ b/core/src/main/java/io/undertow/client/http/HttpRequestConduit.java @@ -100,12 +100,7 @@ private int processWrite(int state, final ByteBuffer userData) throws IOExceptio } ClientRequest request = this.request; ByteBuffer buffer = pooledBuffer.getBuffer(); - Iterator nameIterator = this.nameIterator; - Iterator valueIterator = this.valueIterator; - int charIndex = this.charIndex; int length; - String string = this.string; - HttpString headerName = this.headerName; int res; // BUFFER IS FLIPPED COMING IN if (state != STATE_START && buffer.hasRemaining()) { @@ -189,11 +184,6 @@ private int processWrite(int state, final ByteBuffer userData) throws IOExceptio do { res = next.write(buffer); if (res == 0) { - this.string = string; - this.headerName = headerName; - this.charIndex = charIndex; - this.valueIterator = valueIterator; - this.nameIterator = nameIterator; log.trace("Continuation"); return STATE_HDR_NAME; } @@ -210,11 +200,6 @@ private int processWrite(int state, final ByteBuffer userData) throws IOExceptio res = next.write(buffer); if (res == 0) { log.trace("Continuation"); - this.string = string; - this.headerName = headerName; - this.charIndex = charIndex; - this.valueIterator = valueIterator; - this.nameIterator = nameIterator; return STATE_HDR_D; } } while (buffer.hasRemaining()); @@ -230,11 +215,6 @@ private int processWrite(int state, final ByteBuffer userData) throws IOExceptio res = next.write(buffer); if (res == 0) { log.trace("Continuation"); - this.string = string; - this.headerName = headerName; - this.charIndex = charIndex; - this.valueIterator = valueIterator; - this.nameIterator = nameIterator; return STATE_HDR_DS; } } while (buffer.hasRemaining()); @@ -260,11 +240,6 @@ private int processWrite(int state, final ByteBuffer userData) throws IOExceptio do { res = next.write(buffer); if (res == 0) { - this.string = string; - this.headerName = headerName; - this.charIndex = charIndex; - this.valueIterator = valueIterator; - this.nameIterator = nameIterator; log.trace("Continuation"); return STATE_HDR_VAL; } @@ -467,7 +442,6 @@ private int processWrite(int state, final ByteBuffer userData) throws IOExceptio if (res == 0) { log.trace("Continuation"); this.charIndex = i; - this.string = string; this.state = STATE_URL; return STATE_URL; }