Skip to content

Commit

Permalink
Fix #12356 Do not send keep-alive when not persistent
Browse files Browse the repository at this point in the history
updates from review
  • Loading branch information
gregw committed Oct 11, 2024
1 parent 7dd5f5f commit ceca26a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,19 @@ public HttpField withValue(String value)
return new HttpField(getHeader(), _name, _value + "," + value);
}

/**
* Return a {@link HttpField} with given values (case-insensitive) ensured
* @param values The values to ensure
* @return A new {@link HttpField} if the value was added or this {@link HttpField} if it did contain the value
*/
public HttpField withValues(String... values)
{
HttpField field = this;
for (String value : values)
field = field.withValue(value);
return field;
}

private int nameHashCode()
{
int h = this._hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,20 +644,27 @@ else if (field.contains(HttpHeaderValue.CLOSE.asString()))
_persistent = false;

// Add the field, but without keep-alive
putTo(field.withoutValue(HttpHeaderValue.KEEP_ALIVE.asString()), header);
if (HttpHeaderValue.CLOSE.is(field.getValue()))
putTo(field, header);
else
putTo(field.withoutValue(HttpHeaderValue.KEEP_ALIVE.asString()), header);
}
// Handle Keep-Alive if we are HTTP/10
else if (http10 && _persistent == Boolean.TRUE)
{
// we can't do anything here, so hold the header until we know how we will end the message
http10Connection = field;
if (http10Connection == null)
http10Connection = field;
else
http10Connection = http10Connection.withValues(field.getValues());
}
// Handle connection header without either close nor keep-alive
// Handle connection header without close but with keep-alive
else if (field.contains(HttpHeaderValue.KEEP_ALIVE.asString()))
{
// add the field, but without keep-alive
putTo(field.withoutValue(HttpHeaderValue.KEEP_ALIVE.asString()), header);
}
// Handle connection header without either close or keep-alive
else
{
putTo(field, header);
Expand Down

0 comments on commit ceca26a

Please sign in to comment.