| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.net.urlconnection; | 5 package org.chromium.net.urlconnection; |
| 6 | 6 |
| 7 import org.chromium.net.UrlRequestContext; | 7 import org.chromium.net.CronetEngine; |
| 8 | 8 |
| 9 import java.io.IOException; | 9 import java.io.IOException; |
| 10 import java.net.Proxy; | 10 import java.net.Proxy; |
| 11 import java.net.URL; | 11 import java.net.URL; |
| 12 import java.net.URLConnection; | 12 import java.net.URLConnection; |
| 13 import java.net.URLStreamHandler; | 13 import java.net.URLStreamHandler; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * A {@link URLStreamHandler} that handles HTTP and HTTPS connections. One can u
se this class to | 16 * A {@link URLStreamHandler} that handles HTTP and HTTPS connections. One can u
se this class to |
| 17 * create {@link java.net.HttpURLConnection} instances implemented by Cronet; fo
r example: <pre> | 17 * create {@link java.net.HttpURLConnection} instances implemented by Cronet; fo
r example: <pre> |
| 18 * | 18 * |
| 19 * CronetHttpURLStreamHandler streamHandler = new CronetHttpURLStreamHandler(myC
ontext); | 19 * CronetHttpURLStreamHandler streamHandler = new CronetHttpURLStreamHandler(myC
ontext); |
| 20 * HttpURLConnection connection = (HttpURLConnection)streamHandler.openConnectio
n( | 20 * HttpURLConnection connection = (HttpURLConnection)streamHandler.openConnectio
n( |
| 21 * new URL("http://chromium.org"));</pre> | 21 * new URL("http://chromium.org"));</pre> |
| 22 * <b>Note:</b> Cronet's {@code HttpURLConnection} implementation is subject to
some limitations | 22 * <b>Note:</b> Cronet's {@code HttpURLConnection} implementation is subject to
some limitations |
| 23 * listed {@link CronetURLStreamHandlerFactory here}. | 23 * listed {@link CronetURLStreamHandlerFactory here}. |
| 24 */ | 24 */ |
| 25 public class CronetHttpURLStreamHandler extends URLStreamHandler { | 25 public class CronetHttpURLStreamHandler extends URLStreamHandler { |
| 26 private final UrlRequestContext mUrlRequestContext; | 26 private final CronetEngine mCronetEngine; |
| 27 | 27 |
| 28 public CronetHttpURLStreamHandler(UrlRequestContext urlRequestContext) { | 28 public CronetHttpURLStreamHandler(CronetEngine cronetEngine) { |
| 29 mUrlRequestContext = urlRequestContext; | 29 mCronetEngine = cronetEngine; |
| 30 } | 30 } |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Establishes a new connection to the resource specified by the {@link URL}
{@code url}. | 33 * Establishes a new connection to the resource specified by the {@link URL}
{@code url}. |
| 34 * @return an {@link java.net.HttpURLConnection} instance implemented by Cro
net. | 34 * @return an {@link java.net.HttpURLConnection} instance implemented by Cro
net. |
| 35 */ | 35 */ |
| 36 @Override | 36 @Override |
| 37 public URLConnection openConnection(URL url) throws IOException { | 37 public URLConnection openConnection(URL url) throws IOException { |
| 38 String protocol = url.getProtocol(); | 38 String protocol = url.getProtocol(); |
| 39 if ("http".equals(protocol) || "https".equals(protocol)) { | 39 if ("http".equals(protocol) || "https".equals(protocol)) { |
| 40 return new CronetHttpURLConnection(url, mUrlRequestContext); | 40 return new CronetHttpURLConnection(url, mCronetEngine); |
| 41 } | 41 } |
| 42 throw new UnsupportedOperationException( | 42 throw new UnsupportedOperationException( |
| 43 "Unexpected protocol:" + protocol); | 43 "Unexpected protocol:" + protocol); |
| 44 } | 44 } |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Establishes a new connection to the resource specified by the {@link URL}
{@code url} | 47 * Establishes a new connection to the resource specified by the {@link URL}
{@code url} |
| 48 * using the given proxy. | 48 * using the given proxy. |
| 49 * @return an {@link java.net.HttpURLConnection} instance implemented by Cro
net. | 49 * @return an {@link java.net.HttpURLConnection} instance implemented by Cro
net. |
| 50 */ | 50 */ |
| 51 @Override | 51 @Override |
| 52 public URLConnection openConnection(URL url, Proxy proxy) { | 52 public URLConnection openConnection(URL url, Proxy proxy) { |
| 53 throw new UnsupportedOperationException(); | 53 throw new UnsupportedOperationException(); |
| 54 } | 54 } |
| 55 } | 55 } |
| OLD | NEW |