Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix throwing with HTTP2 unknown settings frame id #2299

Merged
merged 1 commit into from
Jan 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import okhttp3.internal.Util;
import okio.Buffer;
import okio.BufferedSink;
Expand Down Expand Up @@ -268,20 +269,21 @@ public void pushPromise(int streamId, int promisedStreamId, List<Header> headerB
}
}

@Test public void readSettingsFrameInvalidSettingId() throws IOException {
@Test public void readSettingsFrameUnknownSettingId() throws IOException {
writeMedium(frame, 6); // 2 for the code and 4 for the value
frame.writeByte(Http2.TYPE_SETTINGS);
frame.writeByte(Http2.FLAG_NONE);
frame.writeInt(0); // Settings are always on the connection stream 0.
frame.writeShort(7); // old number for SETTINGS_INITIAL_WINDOW_SIZE
frame.writeInt(1);

try {
fr.nextFrame(new BaseTestHandler());
fail();
} catch (IOException e) {
assertEquals("PROTOCOL_ERROR invalid settings id: 7", e.getMessage());
}
final AtomicInteger settingValue = new AtomicInteger();
fr.nextFrame(new BaseTestHandler() {
@Override public void settings(boolean clearPrevious, Settings settings) {
settingValue.set(settings.get(7));
}
});
assertEquals(settingValue.intValue(), 1);
}

@Test public void readSettingsFrameNegativeWindowSize() throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion okhttp/src/main/java/okhttp3/internal/framed/Http2.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private void readSettings(Handler handler, int length, byte flags, int streamId)
case 6: // SETTINGS_MAX_HEADER_LIST_SIZE
break; // Advisory only, so ignored.
default:
throw ioException("PROTOCOL_ERROR invalid settings id: %s", id);
break; // Must ignore setting with unknown id.
}
settings.set(id, 0, value);
}
Expand Down