1/*
2 * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26/*
27 * NOTE: This class lives in the package sun.net.www.protocol.https.
28 * There is a copy in com.sun.net.ssl.internal.www.protocol.https for JSSE
29 * 1.0.2 compatibility. It is 100% identical except the package and extends
30 * lines. Any changes should be made to be class in sun.net.* and then copied
31 * to com.sun.net.*.
32 */
33
34// For both copies of the file, uncomment one line and comment the other
35// package sun.net.www.protocol.https;
36package com.sun.net.ssl.internal.www.protocol.https;
37
38import java.net.URL;
39import java.net.Proxy;
40import java.net.ProtocolException;
41import java.io.*;
42import java.net.Authenticator;
43import javax.net.ssl.*;
44import java.security.Permission;
45import java.util.Map;
46import java.util.List;
47import sun.net.www.http.HttpClient;
48
49/**
50 * A class to represent an HTTP connection to a remote object.
51 *
52 * Ideally, this class should subclass and inherit the http handler
53 * implementation, but it can't do so because that class have the
54 * wrong Java Type.  Thus it uses the delegate (aka, the
55 * Adapter/Wrapper design pattern) to reuse code from the http
56 * handler.
57 *
58 * Since it would use a delegate to access
59 * sun.net.www.protocol.http.HttpURLConnection functionalities, it
60 * needs to implement all public methods in it's super class and all
61 * the way to Object.
62 *
63 */
64
65// For both copies of the file, uncomment one line and comment the other
66// public class HttpsURLConnectionImpl
67//      extends javax.net.ssl.HttpsURLConnection {
68@Deprecated(since="9")
69@SuppressWarnings("deprecation") // HttpsURLConnection is deprecated
70public class HttpsURLConnectionOldImpl
71        extends com.sun.net.ssl.HttpsURLConnection {
72
73    private DelegateHttpsURLConnection delegate;
74
75// For both copies of the file, uncomment one line and comment the other
76//    HttpsURLConnectionImpl(URL u, Handler handler) throws IOException {
77    HttpsURLConnectionOldImpl(URL u, Handler handler) throws IOException {
78        this(u, null, handler);
79    }
80
81// For both copies of the file, uncomment one line and comment the other
82//    HttpsURLConnectionImpl(URL u, Handler handler) throws IOException {
83    HttpsURLConnectionOldImpl(URL u, Proxy p, Handler handler) throws IOException {
84        super(u);
85        delegate = new DelegateHttpsURLConnection(url, p, handler, this);
86    }
87
88    /**
89     * Create a new HttpClient object, bypassing the cache of
90     * HTTP client objects/connections.
91     *
92     * @param url       the URL being accessed
93     */
94    protected void setNewClient(URL url) throws IOException {
95        delegate.setNewClient(url, false);
96    }
97
98    /**
99     * Obtain a HttpClient object. Use the cached copy if specified.
100     *
101     * @param url       the URL being accessed
102     * @param useCache  whether the cached connection should be used
103     *                  if present
104     */
105    protected void setNewClient(URL url, boolean useCache)
106            throws IOException {
107        delegate.setNewClient(url, useCache);
108    }
109
110    /**
111     * Create a new HttpClient object, set up so that it uses
112     * per-instance proxying to the given HTTP proxy.  This
113     * bypasses the cache of HTTP client objects/connections.
114     *
115     * @param url       the URL being accessed
116     * @param proxyHost the proxy host to use
117     * @param proxyPort the proxy port to use
118     */
119    protected void setProxiedClient(URL url, String proxyHost, int proxyPort)
120            throws IOException {
121        delegate.setProxiedClient(url, proxyHost, proxyPort);
122    }
123
124    /**
125     * Obtain a HttpClient object, set up so that it uses per-instance
126     * proxying to the given HTTP proxy. Use the cached copy of HTTP
127     * client objects/connections if specified.
128     *
129     * @param url       the URL being accessed
130     * @param proxyHost the proxy host to use
131     * @param proxyPort the proxy port to use
132     * @param useCache  whether the cached connection should be used
133     *                  if present
134     */
135    protected void setProxiedClient(URL url, String proxyHost, int proxyPort,
136            boolean useCache) throws IOException {
137        delegate.setProxiedClient(url, proxyHost, proxyPort, useCache);
138    }
139
140    /**
141     * Implements the HTTP protocol handler's "connect" method,
142     * establishing an SSL connection to the server as necessary.
143     */
144    public void connect() throws IOException {
145        delegate.connect();
146    }
147
148    /**
149     * Used by subclass to access "connected" variable.  Since we are
150     * delegating the actual implementation to "delegate", we need to
151     * delegate the access of "connected" as well.
152     */
153    protected boolean isConnected() {
154        return delegate.isConnected();
155    }
156
157    /**
158     * Used by subclass to access "connected" variable.  Since we are
159     * delegating the actual implementation to "delegate", we need to
160     * delegate the access of "connected" as well.
161     */
162    protected void setConnected(boolean conn) {
163        delegate.setConnected(conn);
164    }
165
166    /**
167     * Returns the cipher suite in use on this connection.
168     */
169    public String getCipherSuite() {
170        return delegate.getCipherSuite();
171    }
172
173    /**
174     * Returns the certificate chain the client sent to the
175     * server, or null if the client did not authenticate.
176     */
177    public java.security.cert.Certificate []
178        getLocalCertificates() {
179        return delegate.getLocalCertificates();
180    }
181
182    /**
183     * Returns the server's certificate chain, or throws
184     * SSLPeerUnverified Exception if
185     * the server did not authenticate.
186     */
187    public java.security.cert.Certificate []
188        getServerCertificates() throws SSLPeerUnverifiedException {
189        return delegate.getServerCertificates();
190    }
191
192    /*
193     * Allowable input/output sequences:
194     * [interpreted as POST/PUT]
195     * - get output, [write output,] get input, [read input]
196     * - get output, [write output]
197     * [interpreted as GET]
198     * - get input, [read input]
199     * Disallowed:
200     * - get input, [read input,] get output, [write output]
201     */
202
203    public synchronized OutputStream getOutputStream() throws IOException {
204        return delegate.getOutputStream();
205    }
206
207    public synchronized InputStream getInputStream() throws IOException {
208        return delegate.getInputStream();
209    }
210
211    public InputStream getErrorStream() {
212        return delegate.getErrorStream();
213    }
214
215    /**
216     * Disconnect from the server.
217     */
218    public void disconnect() {
219        delegate.disconnect();
220    }
221
222    public boolean usingProxy() {
223        return delegate.usingProxy();
224    }
225
226    /**
227     * Returns an unmodifiable Map of the header fields.
228     * The Map keys are Strings that represent the
229     * response-header field names. Each Map value is an
230     * unmodifiable List of Strings that represents
231     * the corresponding field values.
232     *
233     * @return a Map of header fields
234     * @since 1.4
235     */
236    public Map<String,List<String>> getHeaderFields() {
237        return delegate.getHeaderFields();
238    }
239
240    /**
241     * Gets a header field by name. Returns null if not known.
242     * @param name the name of the header field
243     */
244    public String getHeaderField(String name) {
245        return delegate.getHeaderField(name);
246    }
247
248    /**
249     * Gets a header field by index. Returns null if not known.
250     * @param n the index of the header field
251     */
252    public String getHeaderField(int n) {
253        return delegate.getHeaderField(n);
254    }
255
256    /**
257     * Gets a header field by index. Returns null if not known.
258     * @param n the index of the header field
259     */
260    public String getHeaderFieldKey(int n) {
261        return delegate.getHeaderFieldKey(n);
262    }
263
264    /**
265     * Sets request property. If a property with the key already
266     * exists, overwrite its value with the new value.
267     * @param value the value to be set
268     */
269    public void setRequestProperty(String key, String value) {
270        delegate.setRequestProperty(key, value);
271    }
272
273    /**
274     * Adds a general request property specified by a
275     * key-value pair.  This method will not overwrite
276     * existing values associated with the same key.
277     *
278     * @param   key     the keyword by which the request is known
279     *                  (e.g., "<code>accept</code>").
280     * @param   value  the value associated with it.
281     * @see #getRequestProperties(java.lang.String)
282     * @since 1.4
283     */
284    public void addRequestProperty(String key, String value) {
285        delegate.addRequestProperty(key, value);
286    }
287
288    /**
289     * Overwrite super class method
290     */
291    public int getResponseCode() throws IOException {
292        return delegate.getResponseCode();
293    }
294
295    public String getRequestProperty(String key) {
296        return delegate.getRequestProperty(key);
297    }
298
299    /**
300     * Returns an unmodifiable Map of general request
301     * properties for this connection. The Map keys
302     * are Strings that represent the request-header
303     * field names. Each Map value is a unmodifiable List
304     * of Strings that represents the corresponding
305     * field values.
306     *
307     * @return  a Map of the general request properties for this connection.
308     * @throws IllegalStateException if already connected
309     * @since 1.4
310     */
311    public Map<String,List<String>> getRequestProperties() {
312        return delegate.getRequestProperties();
313    }
314
315    /*
316     * We support JDK 1.2.x so we can't count on these from JDK 1.3.
317     * We override and supply our own version.
318     */
319    public void setInstanceFollowRedirects(boolean shouldFollow) {
320        delegate.setInstanceFollowRedirects(shouldFollow);
321    }
322
323    public boolean getInstanceFollowRedirects() {
324        return delegate.getInstanceFollowRedirects();
325    }
326
327    public void setRequestMethod(String method) throws ProtocolException {
328        delegate.setRequestMethod(method);
329    }
330
331    public String getRequestMethod() {
332        return delegate.getRequestMethod();
333    }
334
335    public String getResponseMessage() throws IOException {
336        return delegate.getResponseMessage();
337    }
338
339    public long getHeaderFieldDate(String name, long Default) {
340        return delegate.getHeaderFieldDate(name, Default);
341    }
342
343    public Permission getPermission() throws IOException {
344        return delegate.getPermission();
345    }
346
347    public URL getURL() {
348        return delegate.getURL();
349    }
350
351    public int getContentLength() {
352        return delegate.getContentLength();
353    }
354
355    public long getContentLengthLong() {
356        return delegate.getContentLengthLong();
357    }
358
359    public String getContentType() {
360        return delegate.getContentType();
361    }
362
363    public String getContentEncoding() {
364        return delegate.getContentEncoding();
365    }
366
367    public long getExpiration() {
368        return delegate.getExpiration();
369    }
370
371    public long getDate() {
372        return delegate.getDate();
373    }
374
375    public long getLastModified() {
376        return delegate.getLastModified();
377    }
378
379    public int getHeaderFieldInt(String name, int Default) {
380        return delegate.getHeaderFieldInt(name, Default);
381    }
382
383    public long getHeaderFieldLong(String name, long Default) {
384        return delegate.getHeaderFieldLong(name, Default);
385    }
386
387    public Object getContent() throws IOException {
388        return delegate.getContent();
389    }
390
391    @SuppressWarnings("rawtypes")
392    public Object getContent(Class[] classes) throws IOException {
393        return delegate.getContent(classes);
394    }
395
396    public String toString() {
397        return delegate.toString();
398    }
399
400    public void setDoInput(boolean doinput) {
401        delegate.setDoInput(doinput);
402    }
403
404    public boolean getDoInput() {
405        return delegate.getDoInput();
406    }
407
408    public void setDoOutput(boolean dooutput) {
409        delegate.setDoOutput(dooutput);
410    }
411
412    public boolean getDoOutput() {
413        return delegate.getDoOutput();
414    }
415
416    public void setAllowUserInteraction(boolean allowuserinteraction) {
417        delegate.setAllowUserInteraction(allowuserinteraction);
418    }
419
420    public boolean getAllowUserInteraction() {
421        return delegate.getAllowUserInteraction();
422    }
423
424    public void setUseCaches(boolean usecaches) {
425        delegate.setUseCaches(usecaches);
426    }
427
428    public boolean getUseCaches() {
429        return delegate.getUseCaches();
430    }
431
432    public void setIfModifiedSince(long ifmodifiedsince) {
433        delegate.setIfModifiedSince(ifmodifiedsince);
434    }
435
436    public long getIfModifiedSince() {
437        return delegate.getIfModifiedSince();
438    }
439
440    public boolean getDefaultUseCaches() {
441        return delegate.getDefaultUseCaches();
442    }
443
444    public void setDefaultUseCaches(boolean defaultusecaches) {
445        delegate.setDefaultUseCaches(defaultusecaches);
446    }
447
448    /*
449     * finalize (dispose) the delegated object.  Otherwise
450     * sun.net.www.protocol.http.HttpURLConnection's finalize()
451     * would have to be made public.
452     */
453    protected void finalize() throws Throwable {
454        delegate.dispose();
455    }
456
457    public boolean equals(Object obj) {
458        return delegate.equals(obj);
459    }
460
461    public int hashCode() {
462        return delegate.hashCode();
463    }
464
465    public void setConnectTimeout(int timeout) {
466        delegate.setConnectTimeout(timeout);
467    }
468
469    public int getConnectTimeout() {
470        return delegate.getConnectTimeout();
471    }
472
473    public void setReadTimeout(int timeout) {
474        delegate.setReadTimeout(timeout);
475    }
476
477    public int getReadTimeout() {
478        return delegate.getReadTimeout();
479    }
480
481    public void setFixedLengthStreamingMode (int contentLength) {
482        delegate.setFixedLengthStreamingMode(contentLength);
483    }
484
485    public void setFixedLengthStreamingMode(long contentLength) {
486        delegate.setFixedLengthStreamingMode(contentLength);
487    }
488
489    public void setChunkedStreamingMode (int chunklen) {
490        delegate.setChunkedStreamingMode(chunklen);
491    }
492
493    @Override
494    public void setAuthenticator(Authenticator auth) {
495        delegate.setAuthenticator(auth);
496    }
497}
498