Skip to content

Commit

Permalink
Rename FramedConnection to Http2Connection.
Browse files Browse the repository at this point in the history
Also rename HttpStream to HttpCodec. This is the interface implemented
for both HTTP/1.1 and HTTP/2. The HTTP/2 codec creates a stream when
it is used.
  • Loading branch information
squarejesse committed Jul 9, 2016
1 parent 33660bf commit 3d43a8d
Show file tree
Hide file tree
Showing 49 changed files with 709 additions and 754 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package okhttp3.internal.framed;
package okhttp3.internal.http2;

import java.io.File;
import java.io.IOException;
Expand All @@ -38,14 +38,14 @@

import static okhttp3.internal.platform.Platform.INFO;

/** A basic HTTP_2 server that serves the contents of a local directory. */
public final class FramedServer extends FramedConnection.Listener {
static final Logger logger = Logger.getLogger(FramedServer.class.getName());
/** A basic HTTP/2 server that serves the contents of a local directory. */
public final class Http2Server extends Http2Connection.Listener {
static final Logger logger = Logger.getLogger(Http2Server.class.getName());

private final File baseDirectory;
private final SSLSocketFactory sslSocketFactory;

public FramedServer(File baseDirectory, SSLSocketFactory sslSocketFactory) {
public Http2Server(File baseDirectory, SSLSocketFactory sslSocketFactory) {
this.baseDirectory = baseDirectory;
this.sslSocketFactory = sslSocketFactory;
}
Expand All @@ -65,11 +65,11 @@ private void run() throws Exception {
if (protocol != Protocol.HTTP_2) {
throw new ProtocolException("Protocol " + protocol + " unsupported");
}
FramedConnection framedConnection = new FramedConnection.Builder(false)
Http2Connection connection = new Http2Connection.Builder(false)
.socket(sslSocket)
.listener(this)
.build();
framedConnection.start();
connection.start();
} catch (IOException e) {
logger.log(Level.INFO, "FramedServer connection failure: " + e);
Util.closeQuietly(socket);
Expand All @@ -90,7 +90,7 @@ private SSLSocket doSsl(Socket socket) throws IOException {
return sslSocket;
}

@Override public void onStream(final FramedStream stream) throws IOException {
@Override public void onStream(final Http2Stream stream) throws IOException {
try {
List<Header> requestHeaders = stream.getRequestHeaders();
String path = null;
Expand Down Expand Up @@ -120,7 +120,7 @@ private SSLSocket doSsl(Socket socket) throws IOException {
}
}

private void send404(FramedStream stream, String path) throws IOException {
private void send404(Http2Stream stream, String path) throws IOException {
List<Header> responseHeaders = Arrays.asList(
new Header(":status", "404"),
new Header(":version", "HTTP/1.1"),
Expand All @@ -132,7 +132,7 @@ private void send404(FramedStream stream, String path) throws IOException {
out.close();
}

private void serveDirectory(FramedStream stream, File[] files) throws IOException {
private void serveDirectory(Http2Stream stream, File[] files) throws IOException {
List<Header> responseHeaders = Arrays.asList(
new Header(":status", "200"),
new Header(":version", "HTTP/1.1"),
Expand All @@ -147,7 +147,7 @@ private void serveDirectory(FramedStream stream, File[] files) throws IOExceptio
out.close();
}

private void serveFile(FramedStream stream, File file) throws IOException {
private void serveFile(Http2Stream stream, File file) throws IOException {
List<Header> responseHeaders = Arrays.asList(
new Header(":status", "200"),
new Header(":version", "HTTP/1.1"),
Expand Down Expand Up @@ -181,7 +181,7 @@ public static void main(String... args) throws Exception {
return;
}

FramedServer server = new FramedServer(new File(args[0]),
Http2Server server = new Http2Server(new File(args[0]),
SslClient.localhost().sslContext.getSocketFactory());
server.run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.concurrent.TimeUnit;
import okhttp3.Headers;
import okhttp3.internal.Internal;
import okhttp3.internal.framed.Settings;
import okhttp3.internal.http2.Settings;
import okhttp3.ws.WebSocketListener;
import okio.Buffer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
import okhttp3.internal.Internal;
import okhttp3.internal.NamedRunnable;
import okhttp3.internal.Util;
import okhttp3.internal.framed.ErrorCode;
import okhttp3.internal.framed.FramedConnection;
import okhttp3.internal.framed.FramedStream;
import okhttp3.internal.framed.Header;
import okhttp3.internal.framed.Settings;
import okhttp3.internal.http.HttpMethod;
import okhttp3.internal.http2.ErrorCode;
import okhttp3.internal.http2.Header;
import okhttp3.internal.http2.Http2Connection;
import okhttp3.internal.http2.Http2Stream;
import okhttp3.internal.http2.Settings;
import okhttp3.internal.platform.Platform;
import okhttp3.internal.ws.RealWebSocket;
import okhttp3.internal.ws.WebSocketProtocol;
Expand Down Expand Up @@ -125,8 +125,8 @@ public final class MockWebServer implements TestRule {

private final Set<Socket> openClientSockets =
Collections.newSetFromMap(new ConcurrentHashMap<Socket, Boolean>());
private final Set<FramedConnection> openFramedConnections =
Collections.newSetFromMap(new ConcurrentHashMap<FramedConnection, Boolean>());
private final Set<Http2Connection> openConnections =
Collections.newSetFromMap(new ConcurrentHashMap<Http2Connection, Boolean>());
private final AtomicInteger requestCount = new AtomicInteger();
private long bodyLimit = Long.MAX_VALUE;
private ServerSocketFactory serverSocketFactory = ServerSocketFactory.getDefault();
Expand Down Expand Up @@ -352,7 +352,7 @@ private synchronized void start(InetSocketAddress inetSocketAddress) throws IOEx
Util.closeQuietly(s.next());
s.remove();
}
for (Iterator<FramedConnection> s = openFramedConnections.iterator(); s.hasNext(); ) {
for (Iterator<Http2Connection> s = openConnections.iterator(); s.hasNext(); ) {
Util.closeQuietly(s.next());
s.remove();
}
Expand Down Expand Up @@ -451,12 +451,12 @@ public void processConnection() throws Exception {

if (protocol == Protocol.HTTP_2) {
FramedSocketHandler framedSocketListener = new FramedSocketHandler(socket, protocol);
FramedConnection framedConnection = new FramedConnection.Builder(false)
Http2Connection connection = new Http2Connection.Builder(false)
.socket(socket)
.listener(framedSocketListener)
.build();
framedConnection.start();
openFramedConnections.add(framedConnection);
connection.start();
openConnections.add(connection);
openClientSockets.remove(socket);
return;
} else if (protocol != Protocol.HTTP_1_1) {
Expand Down Expand Up @@ -842,7 +842,7 @@ private static class TruncatingBuffer implements Sink {
}

/** Processes HTTP requests layered over framed protocols. */
private class FramedSocketHandler extends FramedConnection.Listener {
private class FramedSocketHandler extends Http2Connection.Listener {
private final Socket socket;
private final Protocol protocol;
private final AtomicInteger sequenceNumber = new AtomicInteger();
Expand All @@ -852,7 +852,7 @@ private FramedSocketHandler(Socket socket, Protocol protocol) {
this.protocol = protocol;
}

@Override public void onStream(FramedStream stream) throws IOException {
@Override public void onStream(Http2Stream stream) throws IOException {
MockResponse peekedResponse = dispatcher.peek();
if (peekedResponse.getSocketPolicy() == RESET_STREAM_AT_START) {
try {
Expand Down Expand Up @@ -880,7 +880,7 @@ private FramedSocketHandler(Socket socket, Protocol protocol) {
}
}

private RecordedRequest readRequest(FramedStream stream) throws IOException {
private RecordedRequest readRequest(Http2Stream stream) throws IOException {
List<Header> streamHeaders = stream.getRequestHeaders();
Headers.Builder httpHeaders = new Headers.Builder();
String method = "<:method omitted>";
Expand Down Expand Up @@ -909,7 +909,7 @@ private RecordedRequest readRequest(FramedStream stream) throws IOException {
sequenceNumber.getAndIncrement(), socket);
}

private void writeResponse(FramedStream stream, MockResponse response) throws IOException {
private void writeResponse(Http2Stream stream, MockResponse response) throws IOException {
Settings settings = response.getSettings();
if (settings != null) {
stream.getConnection().setSettings(settings);
Expand Down Expand Up @@ -944,7 +944,7 @@ private void writeResponse(FramedStream stream, MockResponse response) throws IO
}
}

private void pushPromises(FramedStream stream, List<PushPromise> promises) throws IOException {
private void pushPromises(Http2Stream stream, List<PushPromise> promises) throws IOException {
for (PushPromise pushPromise : promises) {
List<Header> pushedHeaders = new ArrayList<>();
pushedHeaders.add(new Header(Header.TARGET_AUTHORITY, url(pushPromise.path()).host()));
Expand All @@ -959,7 +959,7 @@ private void pushPromises(FramedStream stream, List<PushPromise> promises) throw
requestQueue.add(new RecordedRequest(requestLine, pushPromise.headers(), chunkSizes, 0,
new Buffer(), sequenceNumber.getAndIncrement(), socket));
boolean hasBody = pushPromise.response().getBody() != null;
FramedStream pushedStream =
Http2Stream pushedStream =
stream.getConnection().pushStream(stream.getId(), pushedHeaders, hasBody);
writeResponse(pushedStream, pushPromise.response());
}
Expand Down
4 changes: 2 additions & 2 deletions okcurl/src/main/java/okhttp3/curl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.internal.Util;
import okhttp3.internal.framed.Http2;
import okhttp3.internal.http.StatusLine;
import okhttp3.internal.http2.Http2;
import okio.BufferedSource;
import okio.Okio;
import okio.Sink;
Expand Down Expand Up @@ -274,7 +274,7 @@ private static HostnameVerifier createInsecureHostnameVerifier() {
}

private static void enableHttp2FrameLogging() {
frameLogger = Logger.getLogger(Http2.class.getName() + "$FrameLogger");
frameLogger = Logger.getLogger(Http2.class.getName());
frameLogger.setLevel(Level.FINE);
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.internal.framed;
package okhttp3.internal.http2;

import java.util.Collection;
import okhttp3.internal.framed.hpackjson.Story;
import okhttp3.internal.http2.hpackjson.Story;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import static okhttp3.internal.framed.hpackjson.HpackJsonUtil.storiesForCurrentDraft;
import static okhttp3.internal.http2.hpackjson.HpackJsonUtil.storiesForCurrentDraft;

@RunWith(Parameterized.class)
public class HpackDecodeInteropTest extends HpackDecodeTestBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.internal.framed;
package okhttp3.internal.http2;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import okhttp3.internal.framed.hpackjson.Case;
import okhttp3.internal.framed.hpackjson.HpackJsonUtil;
import okhttp3.internal.framed.hpackjson.Story;
import okhttp3.internal.framed.Header;
import okhttp3.internal.framed.Hpack;
import okhttp3.internal.http2.hpackjson.Case;
import okhttp3.internal.http2.hpackjson.HpackJsonUtil;
import okhttp3.internal.http2.hpackjson.Story;
import okio.Buffer;

import static org.junit.Assert.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.internal.framed;
package okhttp3.internal.http2;

import java.util.Collection;
import okhttp3.internal.framed.hpackjson.Case;
import okhttp3.internal.framed.hpackjson.Story;
import okhttp3.internal.framed.Hpack;
import okhttp3.internal.http2.hpackjson.Case;
import okhttp3.internal.http2.hpackjson.Story;
import okio.Buffer;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.internal.framed.hpackjson;
package okhttp3.internal.http2.hpackjson;

import java.util.ArrayList;
import java.util.LinkedHashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.internal.framed.hpackjson;
package okhttp3.internal.http2.hpackjson;

import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.internal.framed.hpackjson;
package okhttp3.internal.http2.hpackjson;

import java.util.ArrayList;
import java.util.List;
Expand Down
2 changes: 0 additions & 2 deletions okhttp-tests/src/test/java/okhttp3/ConnectionReuseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSocketFactory;
import okhttp3.internal.tls.SslClient;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
Expand Down
8 changes: 4 additions & 4 deletions okhttp-tests/src/test/java/okhttp3/HeadersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.List;
import java.util.Map;
import okhttp3.internal.Internal;
import okhttp3.internal.framed.Header;
import okhttp3.internal.http.Http2xStream;
import okhttp3.internal.http2.Header;
import okhttp3.internal.http2.Http2Codec;
import org.junit.Test;

import static okhttp3.TestUtil.headerEntries;
Expand All @@ -43,7 +43,7 @@ public final class HeadersTest {
":version", "HTTP/1.1",
"connection", "close");
Request request = new Request.Builder().url("http://square.com/").build();
Response response = Http2xStream.readHttp2HeadersList(headerBlock).request(request).build();
Response response = Http2Codec.readHttp2HeadersList(headerBlock).request(request).build();
Headers headers = response.headers();
assertEquals(1, headers.size());
assertEquals(":version", headers.name(0));
Expand All @@ -61,7 +61,7 @@ public final class HeadersTest {
":path", "/",
":authority", "square.com",
":scheme", "http");
assertEquals(expected, Http2xStream.http2HeadersList(request));
assertEquals(expected, Http2Codec.http2HeadersList(request));
}

@Test public void ofTrims() {
Expand Down
2 changes: 1 addition & 1 deletion okhttp-tests/src/test/java/okhttp3/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Arrays;
import java.util.List;
import okhttp3.internal.SingleInetAddressDns;
import okhttp3.internal.framed.Header;
import okhttp3.internal.http2.Header;

public final class TestUtil {
private TestUtil() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.internal.framed;
package okhttp3.internal.http2;

import java.io.IOException;
import java.util.List;
Expand All @@ -22,7 +22,7 @@

import static org.junit.Assert.fail;

class BaseTestHandler implements FrameReader.Handler {
class BaseTestHandler implements Http2Reader.Handler {
@Override public void data(boolean inFinished, int streamId, BufferedSource source, int length)
throws IOException {
fail();
Expand Down
Loading

0 comments on commit 3d43a8d

Please sign in to comment.