Skip to content

Commit

Permalink
UNDERTOW-2017: HttpRequestConduit state is correctly maintained
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carterkozak committed Jan 14, 2022
1 parent b24d455 commit 3491181
Showing 1 changed file with 0 additions and 26 deletions.
26 changes: 0 additions & 26 deletions core/src/main/java/io/undertow/client/http/HttpRequestConduit.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ private int processWrite(int state, final ByteBuffer userData) throws IOExceptio
}
ClientRequest request = this.request;
ByteBuffer buffer = pooledBuffer.getBuffer();
Iterator<HttpString> nameIterator = this.nameIterator;
Iterator<String> 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()) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3491181

Please sign in to comment.