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

Initial implementation of an OkHttp-backed curl clone. #514

Merged
merged 1 commit into from
Feb 8, 2014

Conversation

JakeWharton
Copy link
Collaborator

Supports (and mirrors directly) a few of the options provided by curl. Most notably missing is the ability to change the HTTP method, force the protocol, supply a body, and verbose logging of connection information. These will be added in subsequent changes.

Request request = getConfiguredRequest();
client.enqueue(request, this);

// Immediately begin triggering an executor shutdown so that after execution of the above
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. . . policy here is tricky. I don't think they should be daemon threads unless they're idle. Unfortunately that isn't an option. Dumb.

@swankjesse
Copy link
Collaborator

Nice!

@swankjesse
Copy link
Collaborator

LGTM

@codefromthecrypt
Copy link

I bet @brianm will love this


private static String protocols() {
return Joiner.on(", ")
.join(FluentIterable.from(Arrays.asList(Protocol.values()))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Lists.transform would be a little shorter

@codefromthecrypt
Copy link

heh.. the following does actually work to add NPN support!

+        <configuration>
+          <flags>-Xbootclasspath/p:$0</flags>
+        </configuration>

@codefromthecrypt
Copy link

ps right now, there's no way to shutdown the spdy daemon threads, so we should System.exit after main or create some thing to shut the threads down.

@codefromthecrypt
Copy link

addressed my comments. Note that the async nature of this is not shutting down the reader thread. This causes okcurl to hang on spdy connections.

It would be simpler to just make this use UrlConnection, so that it can call disconnect and close properly. Unless someone is opposed, I'd prefer making this change.

@codefromthecrypt
Copy link

@JakeWharton judgement call time. I added a commit which uses HttpUrlConnection and doesn't need the changes to Dispatcher. Lemme know how you feel about it.

@swankjesse
Copy link
Collaborator

@adriancole no not HttpURLConnection! Our new async API is the future. Maybe we want a method on ConnectionPool to prune idle connections?

@codefromthecrypt
Copy link

going to try something that hopefully can kill the last commit!

if (allowInsecure) {
client.setSslSocketFactory(createInsecureSslSocketFactory());
}
client.setConnectionPool(ConnectionPool.getDefault());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't set this reference, there's no way to clean shutdown persistent connections

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add as comment?

@codefromthecrypt
Copy link

OK. looks like we are in business!

~/Development/okhttp/okcurl jw/okcurl target/okcurl-2.0.0-SNAPSHOT-jar-with-dependencies.jar -i https://google.com
HTTP/1.1 301 Moved Permanently
OkHttp-Selected-Transport: spdy/3.1
OkHttp-Selected-Protocol: spdy/3.1
alternate-protocol: 443:quic
cache-control: public, max-age=2592000
content-length: 220
content-type: text/html; charset=UTF-8
date: Sat, 08 Feb 2014 22:35:00 GMT
expires: Mon, 10 Mar 2014 22:35:00 GMT
location: https://www.google.com/
server: gws
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
OkHttp-Sent-Millis: 1391898900226
OkHttp-Received-Millis: 1391898900882
OkHttp-Response-Source: NETWORK 301

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

}

private void close() {
client.getConnectionPool().evictAll(); // close any persistent connections.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: capitalize sentence

@JakeWharton
Copy link
Collaborator Author

lgtm!

@codefromthecrypt
Copy link

okie notes addressed.

@codefromthecrypt
Copy link

awesome, jake! now we have a curl that supports spdy and http/2!

@JakeWharton
Copy link
Collaborator Author

Got a single test failing.

@codefromthecrypt
Copy link

it's a flake.. probably need to throw another round of flake-be-gone soon.

JakeWharton added a commit that referenced this pull request Feb 8, 2014
Initial implementation of an OkHttp-backed curl clone.
@JakeWharton JakeWharton merged commit de6d505 into master Feb 8, 2014
@JakeWharton JakeWharton deleted the jw/okcurl branch February 8, 2014 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants