Skip to content

Commit

Permalink
Merge pull request square#1708 from square/jw/framed
Browse files Browse the repository at this point in the history
Rename 'spdy' references to 'framed' where appropriate.
  • Loading branch information
swankjesse committed Jun 18, 2015
2 parents b262f2a + c753d2e commit 037deb8
Show file tree
Hide file tree
Showing 42 changed files with 375 additions and 374 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.squareup.okhttp.internal.spdy;
package com.squareup.okhttp.internal.framed;

import com.squareup.okhttp.Protocol;
import com.squareup.okhttp.internal.Platform;
Expand All @@ -36,15 +36,16 @@
import okio.Source;

/** A basic SPDY/HTTP_2 server that serves the contents of a local directory. */
public final class SpdyServer implements IncomingStreamHandler {
static final Logger logger = Logger.getLogger(SpdyServer.class.getName());
public final class FramedServer implements IncomingStreamHandler {
static final Logger logger = Logger.getLogger(FramedServer.class.getName());

private final List<Protocol> spdyProtocols = Util.immutableList(Protocol.HTTP_2, Protocol.SPDY_3);
private final List<Protocol> framedProtocols =
Util.immutableList(Protocol.HTTP_2, Protocol.SPDY_3);

private final File baseDirectory;
private final SSLSocketFactory sslSocketFactory;

public SpdyServer(File baseDirectory, SSLSocketFactory sslSocketFactory) {
public FramedServer(File baseDirectory, SSLSocketFactory sslSocketFactory) {
this.baseDirectory = baseDirectory;
this.sslSocketFactory = sslSocketFactory;
}
Expand All @@ -61,19 +62,19 @@ private void run() throws Exception {
SSLSocket sslSocket = doSsl(socket);
String protocolString = Platform.get().getSelectedProtocol(sslSocket);
Protocol protocol = protocolString != null ? Protocol.get(protocolString) : null;
if (protocol == null || !spdyProtocols.contains(protocol)) {
if (protocol == null || !framedProtocols.contains(protocol)) {
throw new ProtocolException("Protocol " + protocol + " unsupported");
}
SpdyConnection spdyConnection = new SpdyConnection.Builder(false, sslSocket)
FramedConnection framedConnection = new FramedConnection.Builder(false, sslSocket)
.protocol(protocol)
.handler(this)
.build();
spdyConnection.sendConnectionPreface();
framedConnection.sendConnectionPreface();
} catch (IOException e) {
logger.log(Level.INFO, "SpdyServer connection failure: " + e);
logger.log(Level.INFO, "FramedServer connection failure: " + e);
Util.closeQuietly(socket);
} catch (Exception e) {
logger.log(Level.WARNING, "SpdyServer unexpected failure", e);
logger.log(Level.WARNING, "FramedServer unexpected failure", e);
Util.closeQuietly(socket);
}
}
Expand All @@ -83,12 +84,12 @@ private SSLSocket doSsl(Socket socket) throws IOException {
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true);
sslSocket.setUseClientMode(false);
Platform.get().configureTlsExtensions(sslSocket, null, spdyProtocols);
Platform.get().configureTlsExtensions(sslSocket, null, framedProtocols);
sslSocket.startHandshake();
return sslSocket;
}

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

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

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

private void serveFile(SpdyStream stream, File file) throws IOException {
private void serveFile(FramedStream stream, File file) throws IOException {
List<Header> responseHeaders = Arrays.asList(
new Header(":status", "200"),
new Header(":version", "HTTP/1.1"),
Expand Down Expand Up @@ -175,11 +176,11 @@ private String contentType(File file) {

public static void main(String... args) throws Exception {
if (args.length != 1 || args[0].startsWith("-")) {
System.out.println("Usage: SpdyServer <base directory>");
System.out.println("Usage: FramedServer <base directory>");
return;
}

SpdyServer server = new SpdyServer(new File(args[0]),
FramedServer server = new FramedServer(new File(args[0]),
SslContextBuilder.localhost().getSocketFactory());
server.run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import com.squareup.okhttp.internal.NamedRunnable;
import com.squareup.okhttp.internal.Platform;
import com.squareup.okhttp.internal.Util;
import com.squareup.okhttp.internal.spdy.ErrorCode;
import com.squareup.okhttp.internal.spdy.Header;
import com.squareup.okhttp.internal.spdy.IncomingStreamHandler;
import com.squareup.okhttp.internal.spdy.SpdyConnection;
import com.squareup.okhttp.internal.spdy.SpdyStream;
import com.squareup.okhttp.internal.framed.ErrorCode;
import com.squareup.okhttp.internal.framed.FramedConnection;
import com.squareup.okhttp.internal.framed.FramedStream;
import com.squareup.okhttp.internal.framed.Header;
import com.squareup.okhttp.internal.framed.IncomingStreamHandler;
import com.squareup.okhttp.internal.ws.RealWebSocket;
import com.squareup.okhttp.internal.ws.WebSocketProtocol;
import com.squareup.okhttp.ws.WebSocketListener;
Expand Down Expand Up @@ -107,8 +107,8 @@ public final class MockWebServer {

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

if (protocol != Protocol.HTTP_1_1) {
SpdySocketHandler spdySocketHandler = new SpdySocketHandler(socket, protocol);
SpdyConnection spdyConnection =
new SpdyConnection.Builder(false, socket).protocol(protocol)
.handler(spdySocketHandler)
FramedSocketHandler framedSocketHandler = new FramedSocketHandler(socket, protocol);
FramedConnection framedConnection =
new FramedConnection.Builder(false, socket).protocol(protocol)
.handler(framedSocketHandler)
.build();
openSpdyConnections.add(spdyConnection);
openFramedConnections.add(framedConnection);
openClientSockets.remove(socket);
return;
}
Expand Down Expand Up @@ -809,18 +809,18 @@ private static class TruncatingBuffer implements Sink {
}
}

/** Processes HTTP requests layered over SPDY/3. */
private class SpdySocketHandler implements IncomingStreamHandler {
/** Processes HTTP requests layered over framed protocols. */
private class FramedSocketHandler implements IncomingStreamHandler {
private final Socket socket;
private final Protocol protocol;
private final AtomicInteger sequenceNumber = new AtomicInteger();

private SpdySocketHandler(Socket socket, Protocol protocol) {
private FramedSocketHandler(Socket socket, Protocol protocol) {
this.socket = socket;
this.protocol = protocol;
}

@Override public void receive(SpdyStream stream) throws IOException {
@Override public void receive(FramedStream stream) throws IOException {
RecordedRequest request = readRequest(stream);
requestQueue.add(request);
MockResponse response;
Expand All @@ -836,15 +836,15 @@ private SpdySocketHandler(Socket socket, Protocol protocol) {
}
}

private RecordedRequest readRequest(SpdyStream stream) throws IOException {
List<Header> spdyHeaders = stream.getRequestHeaders();
private RecordedRequest readRequest(FramedStream stream) throws IOException {
List<Header> streamHeaders = stream.getRequestHeaders();
Headers.Builder httpHeaders = new Headers.Builder();
String method = "<:method omitted>";
String path = "<:path omitted>";
String version = protocol == Protocol.SPDY_3 ? "<:version omitted>" : "HTTP/1.1";
for (int i = 0, size = spdyHeaders.size(); i < size; i++) {
ByteString name = spdyHeaders.get(i).name;
String value = spdyHeaders.get(i).value.utf8();
for (int i = 0, size = streamHeaders.size(); i < size; i++) {
ByteString name = streamHeaders.get(i).name;
String value = streamHeaders.get(i).value.utf8();
if (name.equals(Header.TARGET_METHOD)) {
method = value;
} else if (name.equals(Header.TARGET_PATH)) {
Expand All @@ -866,7 +866,7 @@ private RecordedRequest readRequest(SpdyStream stream) throws IOException {
sequenceNumber.getAndIncrement(), socket);
}

private void writeResponse(SpdyStream stream, MockResponse response) throws IOException {
private void writeResponse(FramedStream stream, MockResponse response) throws IOException {
if (response.getSocketPolicy() == SocketPolicy.NO_RESPONSE) {
return;
}
Expand Down Expand Up @@ -899,7 +899,7 @@ private void writeResponse(SpdyStream stream, MockResponse response) throws IOEx
}
}

private void pushPromises(SpdyStream stream, List<PushPromise> promises) throws IOException {
private void pushPromises(FramedStream stream, List<PushPromise> promises) throws IOException {
for (PushPromise pushPromise : promises) {
List<Header> pushedHeaders = new ArrayList<>();
pushedHeaders.add(new Header(stream.getConnection().getProtocol() == Protocol.SPDY_3
Expand All @@ -916,7 +916,7 @@ private void pushPromises(SpdyStream stream, List<PushPromise> promises) throws
requestQueue.add(new RecordedRequest(requestLine, pushPromise.getHeaders(), chunkSizes, 0,
new Buffer(), sequenceNumber.getAndIncrement(), socket));
boolean hasBody = pushPromise.getResponse().getBody() != null;
SpdyStream pushedStream =
FramedStream pushedStream =
stream.getConnection().pushStream(stream.getId(), pushedHeaders, hasBody);
writeResponse(pushedStream, pushPromise.getResponse());
}
Expand Down
2 changes: 1 addition & 1 deletion okcurl/src/main/java/com/squareup/okhttp/curl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.internal.http.StatusLine;
import com.squareup.okhttp.internal.spdy.Http2;
import com.squareup.okhttp.internal.framed.Http2;

import io.airlift.command.Arguments;
import io.airlift.command.Command;
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 com.squareup.okhttp.internal.spdy;
package com.squareup.okhttp.internal.framed;

import com.squareup.okhttp.internal.spdy.hpackjson.Story;
import com.squareup.okhttp.internal.framed.hpackjson.Story;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import static com.squareup.okhttp.internal.spdy.hpackjson.HpackJsonUtil.storiesForCurrentDraft;
import static com.squareup.okhttp.internal.framed.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,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.okhttp.internal.spdy;
package com.squareup.okhttp.internal.framed;

import com.squareup.okhttp.internal.spdy.hpackjson.Case;
import com.squareup.okhttp.internal.spdy.hpackjson.HpackJsonUtil;
import com.squareup.okhttp.internal.spdy.hpackjson.Story;
import com.squareup.okhttp.internal.framed.hpackjson.Case;
import com.squareup.okhttp.internal.framed.hpackjson.HpackJsonUtil;
import com.squareup.okhttp.internal.framed.hpackjson.Story;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.okhttp.internal.spdy;
package com.squareup.okhttp.internal.framed;

import com.squareup.okhttp.internal.spdy.hpackjson.Case;
import com.squareup.okhttp.internal.spdy.hpackjson.Story;
import com.squareup.okhttp.internal.framed.hpackjson.Case;
import com.squareup.okhttp.internal.framed.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,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.okhttp.internal.spdy.hpackjson;
package com.squareup.okhttp.internal.framed.hpackjson;

import com.squareup.okhttp.internal.spdy.Header;
import com.squareup.okhttp.internal.framed.Header;
import okio.ByteString;

import java.util.ArrayList;
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 com.squareup.okhttp.internal.spdy.hpackjson;
package com.squareup.okhttp.internal.framed.hpackjson;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -86,4 +86,4 @@ public static List<Story> readStories(String testFolderName) throws Exception {
}

private HpackJsonUtil() { } // Utilities only.
}
}
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 com.squareup.okhttp.internal.spdy.hpackjson;
package com.squareup.okhttp.internal.framed.hpackjson;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.squareup.okhttp;

import com.squareup.okhttp.internal.spdy.Header;
import com.squareup.okhttp.internal.framed.Header;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
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 com.squareup.okhttp.internal.spdy;
package com.squareup.okhttp.internal.framed;

import java.io.IOException;
import java.util.List;
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 com.squareup.okhttp.internal.spdy;
package com.squareup.okhttp.internal.framed;

import java.io.IOException;
import java.util.Arrays;
Expand Down
Loading

0 comments on commit 037deb8

Please sign in to comment.