Skip to content

Commit

Permalink
Merge pull request #10 from square/master
Browse files Browse the repository at this point in the history
sync origin
  • Loading branch information
carck committed Jan 29, 2014
2 parents 2de994b + a3db2d7 commit 29ea39c
Show file tree
Hide file tree
Showing 41 changed files with 1,910 additions and 482 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ language: java
notifications:
email: false

before_install:
- mvn -version

jdk:
- oraclejdk7
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ License
[2]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=okhttp&v=LATEST&c=jar-with-dependencies
[3]: http://wiki.eclipse.org/Jetty/Feature/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&c=jar-with-dependencies
[5]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.okhttp&a=mockwebserver&v=LATEST
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.squareup.okhttp.mockwebserver;

import com.squareup.okhttp.Protocol;
import com.squareup.okhttp.internal.ByteString;
import com.squareup.okhttp.internal.bytes.ByteString;
import com.squareup.okhttp.internal.NamedRunnable;
import com.squareup.okhttp.internal.Platform;
import com.squareup.okhttp.internal.Util;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.squareup.okhttp;

import com.squareup.okhttp.internal.ByteString;
import com.squareup.okhttp.internal.bytes.ByteString;
import com.squareup.okhttp.internal.Util;
import java.io.IOException;
import java.util.Arrays;
Expand All @@ -26,16 +26,16 @@
* <a href="http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04">NPN</a> or
* <a href="http://tools.ietf.org/html/draft-ietf-tls-applayerprotoneg">ALPN</a> selection.
*
* <p/>
* <p>
* <h3>Protocol vs Scheme</h3>
* Despite its name, {@link java.net.URL#getProtocol()} returns the
* {@link java.net.URI#getScheme() scheme} (http, https, etc.) of the URL, not
* the protocol (http/1.1, spdy/3, etc.). OkHttp uses the word protocol to
* the protocol (http/1.1, spdy/3.1, etc.). OkHttp uses the word protocol to
* indicate how HTTP messages are framed.
*/
public enum Protocol {
HTTP_2("HTTP-draft-09/2.0", true),
SPDY_3("spdy/3", true),
SPDY_3("spdy/3.1", true),
HTTP_11("http/1.1", false);

public static final List<Protocol> HTTP2_SPDY3_AND_HTTP =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.squareup.okhttp.internal;

import com.squareup.okhttp.Protocol;
import com.squareup.okhttp.internal.bytes.ByteString;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -44,7 +45,7 @@
* <h3>ALPN and NPN</h3>
* This class uses TLS extensions ALPN and NPN to negotiate the upgrade from
* HTTP/1.1 (the default protocol to use with TLS on port 443) to either SPDY
* or HTTP/2.0.
* or HTTP/2.
*
* <p>NPN (Next Protocol Negotiation) was developed for SPDY. It is widely
* available and we support it on both Android (4.1+) and OpenJDK 7 (via the
Expand Down Expand Up @@ -339,7 +340,7 @@ public JdkWithJettyNpnPlatform(Method putMethod, Method getMethod, Class<?> clie
if (!provider.unsupported && provider.selected == null) {
Logger logger = Logger.getLogger("com.squareup.okhttp.OkHttpClient");
logger.log(Level.INFO,
"NPN callback dropped so SPDY is disabled. " + "Is npn-boot on the boot class path?");
"NPN callback dropped so SPDY is disabled. Is npn-boot on the boot class path?");
return null;
}
return provider.unsupported ? null : ByteString.encodeUtf8(provider.selected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.okhttp.internal;
package com.squareup.okhttp.internal.bytes;

import com.squareup.okhttp.internal.Util;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -34,7 +35,7 @@
* process.
*/
public final class ByteString {
private final byte[] data;
final byte[] data;
private transient int hashCode; // Lazily computed; 0 if unknown.
private transient String utf8; // Lazily computed.

Expand Down Expand Up @@ -119,7 +120,7 @@ public static ByteString concat(ByteString... byteStrings) {
return new ByteString(result);
}

private ByteString(byte[] data) {
ByteString(byte[] data) {
this.data = data; // Trusted internal constructor doesn't clone data.
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2014 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.okhttp.internal.bytes;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
* The time that a requested operation is due. If the deadline is reached before
* the operation has completed, the operation should be aborted.
*/
public class Deadline {
public static final Deadline NONE = new Deadline() {
@Override public Deadline start(long timeout, TimeUnit unit) {
throw new UnsupportedOperationException();
}

@Override public boolean reached() {
return false;
}
};

private long deadlineNanos;

public Deadline() {
}

public Deadline start(long timeout, TimeUnit unit) {
deadlineNanos = System.nanoTime() + unit.toNanos(timeout);
return this;
}

public boolean reached() {
return System.nanoTime() - deadlineNanos >= 0; // Subtract to avoid overflow!
}

public void throwIfReached() throws IOException {
// TODO: a more catchable exception type?
if (reached()) throw new IOException("Deadline reached");
}
}
Loading

0 comments on commit 29ea39c

Please sign in to comment.