Fix memory leak in DefaultHttp2Headers
Motivation: Memory leak makes headers non-reusable. Modifications: Correctly reset firstNonPseudo header reference Result: No leak
This commit is contained in:
parent
3eb65797ed
commit
7cc320ce47
@ -90,6 +90,12 @@ public class DefaultHttp2Headers
|
||||
validate ? HTTP2_NAME_VALIDATOR : NameValidator.NOT_NULL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Http2Headers clear() {
|
||||
this.firstNonPseudo = head;
|
||||
return super.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Http2Headers method(CharSequence value) {
|
||||
set(PseudoHeaderName.METHOD.value(), value);
|
||||
|
@ -22,6 +22,7 @@ import org.junit.Test;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -74,6 +75,16 @@ public class DefaultHttp2HeadersTest {
|
||||
headers.add(of("Foo"), of("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearResetsPseudoHeaderDivision() {
|
||||
DefaultHttp2Headers http2Headers = new DefaultHttp2Headers();
|
||||
http2Headers.method("POST");
|
||||
http2Headers.set("some", "value");
|
||||
http2Headers.clear();
|
||||
http2Headers.method("GET");
|
||||
assertEquals(1, http2Headers.names().size());
|
||||
}
|
||||
|
||||
private static void verifyAllPseudoHeadersPresent(Http2Headers headers) {
|
||||
for (PseudoHeaderName pseudoName : PseudoHeaderName.values()) {
|
||||
assertNotNull(headers.get(pseudoName.value()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user