mirror of
https://github.com/square/okhttp.git
synced 2026-01-18 20:40:58 +03:00
Merge pull request #771 from square/adrian.okcurl-frames
Add --frames arg to okcurl, which sends HTTP/2 frame metadata to STDERR.
This commit is contained in:
@@ -35,7 +35,7 @@ Testing
|
||||
### On the Desktop
|
||||
|
||||
Run OkHttp tests on the desktop with Maven. Running SPDY tests on the desktop uses
|
||||
[Jetty-NPN][3] which requires OpenJDK 7+.
|
||||
[Jetty-NPN][3] which requires OpenJDK 7.
|
||||
|
||||
```
|
||||
mvn clean test
|
||||
@@ -101,6 +101,6 @@ License
|
||||
|
||||
[1]: http://square.github.io/okhttp
|
||||
[2]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=okhttp&v=LATEST
|
||||
[3]: http://wiki.eclipse.org/Jetty/Feature/NPN
|
||||
[3]: https://github.com/jetty-project/jetty-npn
|
||||
[4]: https://code.google.com/p/vogar/
|
||||
[5]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=mockwebserver&v=LATEST
|
||||
|
||||
@@ -17,27 +17,29 @@
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import com.squareup.okhttp.Protocol;
|
||||
import com.squareup.okhttp.internal.Platform;
|
||||
import com.squareup.okhttp.internal.SslContextBuilder;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import okio.BufferedSink;
|
||||
import okio.Okio;
|
||||
import okio.Source;
|
||||
import org.eclipse.jetty.npn.NextProtoNego;
|
||||
|
||||
import static com.squareup.okhttp.internal.Util.headerEntries;
|
||||
|
||||
/** A basic SPDY server that serves the contents of a local directory. */
|
||||
/** A basic SPDY/HTTP_2 server that serves the contents of a local directory. */
|
||||
public final class SpdyServer implements IncomingStreamHandler {
|
||||
private final List<Protocol> spdyProtocols = Util.immutableList(Protocol.HTTP_2, Protocol.SPDY_3);
|
||||
|
||||
private final File baseDirectory;
|
||||
private SSLSocketFactory sslSocketFactory;
|
||||
private Protocol protocol;
|
||||
|
||||
public SpdyServer(File baseDirectory) {
|
||||
this.baseDirectory = baseDirectory;
|
||||
@@ -56,7 +58,7 @@ public final class SpdyServer implements IncomingStreamHandler {
|
||||
if (sslSocketFactory != null) {
|
||||
socket = doSsl(socket);
|
||||
}
|
||||
new SpdyConnection.Builder(false, socket).handler(this).build();
|
||||
new SpdyConnection.Builder(false, socket).protocol(protocol).handler(this).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,17 +67,13 @@ public final class SpdyServer implements IncomingStreamHandler {
|
||||
(SSLSocket) sslSocketFactory.createSocket(socket, socket.getInetAddress().getHostAddress(),
|
||||
socket.getPort(), true);
|
||||
sslSocket.setUseClientMode(false);
|
||||
NextProtoNego.put(sslSocket, new NextProtoNego.ServerProvider() {
|
||||
@Override public void unsupported() {
|
||||
System.out.println("UNSUPPORTED");
|
||||
}
|
||||
@Override public List<String> protocols() {
|
||||
return Arrays.asList(Protocol.SPDY_3.toString());
|
||||
}
|
||||
@Override public void protocolSelected(String protocol) {
|
||||
System.out.println("PROTOCOL SELECTED: " + protocol);
|
||||
}
|
||||
});
|
||||
Platform.get().setNpnProtocols(sslSocket, spdyProtocols);
|
||||
sslSocket.startHandshake();
|
||||
String protocolString = Platform.get().getNpnSelectedProtocol(sslSocket);
|
||||
protocol = protocolString != null ? Protocol.get(protocolString) : null;
|
||||
if (protocol == null || !spdyProtocols.contains(protocol)) {
|
||||
throw new IllegalStateException("Protocol " + protocol + " unsupported");
|
||||
}
|
||||
return sslSocket;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.squareup.okhttp.Protocol;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.Response;
|
||||
import com.squareup.okhttp.internal.http.StatusLine;
|
||||
import com.squareup.okhttp.internal.spdy.Http20Draft10;
|
||||
import io.airlift.command.Arguments;
|
||||
import io.airlift.command.Command;
|
||||
import io.airlift.command.HelpOption;
|
||||
@@ -35,6 +36,11 @@ import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
@@ -102,6 +108,9 @@ public class Main extends HelpOption implements Runnable {
|
||||
@Option(name = { "-i", "--include" }, description = "Include protocol headers in the output")
|
||||
public boolean showHeaders;
|
||||
|
||||
@Option(name = "--frames", description = "Log HTTP/2 frames to STDERR")
|
||||
public boolean showHttp2Frames;
|
||||
|
||||
@Option(name = { "-e", "--referer" }, description = "Referer URL")
|
||||
public String referer;
|
||||
|
||||
@@ -123,6 +132,10 @@ public class Main extends HelpOption implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
if (showHttp2Frames) {
|
||||
enableHttp2FrameLogging();
|
||||
}
|
||||
|
||||
client = createClient();
|
||||
Request request = createRequest();
|
||||
try {
|
||||
@@ -249,4 +262,17 @@ public class Main extends HelpOption implements Runnable {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static void enableHttp2FrameLogging() {
|
||||
Logger logger = Logger.getLogger(Http20Draft10.class.getName());
|
||||
logger.setLevel(Level.FINE);
|
||||
ConsoleHandler handler = new ConsoleHandler();
|
||||
handler.setLevel(Level.FINE);
|
||||
handler.setFormatter(new SimpleFormatter() {
|
||||
@Override public String format(LogRecord record) {
|
||||
return String.format("%s%n", record.getMessage());
|
||||
}
|
||||
});
|
||||
logger.addHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user