1 /* 2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved. 3 * Please refer to the LICENSE.txt for licensing details. 4 */ 5 package ch.ethz.ssh2; 6 7 /** 8 * A <code>HTTPProxyData</code> object is used to specify the needed connection data 9 * to connect through a HTTP proxy. 10 * 11 * @see Connection#setProxyData(ProxyData) 12 * 13 * @author Christian Plattner 14 * @version 2.50, 03/15/10 15 */ 16 17 public class HTTPProxyData implements ProxyData 18 { 19 public final String proxyHost; 20 public final int proxyPort; 21 public final String proxyUser; 22 public final String proxyPass; 23 public final String[] requestHeaderLines; 24 25 /** 26 * Same as calling {@link #HTTPProxyData(String, int, String, String) HTTPProxyData(proxyHost, proxyPort, <code>null</code>, <code>null</code>)} 27 * 28 * @param proxyHost Proxy hostname. 29 * @param proxyPort Proxy port. 30 */ 31 public HTTPProxyData(String proxyHost, int proxyPort) 32 { 33 this(proxyHost, proxyPort, null, null); 34 } 35 36 /** 37 * Same as calling {@link #HTTPProxyData(String, int, String, String, String[]) HTTPProxyData(proxyHost, proxyPort, <code>null</code>, <code>null</code>, <code>null</code>)} 38 * 39 * @param proxyHost Proxy hostname. 40 * @param proxyPort Proxy port. 41 * @param proxyUser Username for basic authentication (<code>null</code> if no authentication is needed). 42 * @param proxyPass Password for basic authentication (<code>null</code> if no authentication is needed). 43 */ 44 public HTTPProxyData(String proxyHost, int proxyPort, String proxyUser, String proxyPass) 45 { 46 this(proxyHost, proxyPort, proxyUser, proxyPass, null); 47 } 48 49 /** 50 * Connection data for a HTTP proxy. It is possible to specify a username and password 51 * if the proxy requires basic authentication. Also, additional request header lines can 52 * be specified (e.g., "User-Agent: CERN-LineMode/2.15 libwww/2.17b3"). 53 * <p> 54 * Please note: if you want to use basic authentication, then both <code>proxyUser</code> 55 * and <code>proxyPass</code> must be non-null. 56 * <p> 57 * Here is an example: 58 * <p> 59 * <code> 60 * new HTTPProxyData("192.168.1.1", "3128", "proxyuser", "secret", new String[] {"User-Agent: GanymedBasedClient/1.0", "X-My-Proxy-Option: something"}); 61 * </code> 62 * 63 * @param proxyHost Proxy hostname. 64 * @param proxyPort Proxy port. 65 * @param proxyUser Username for basic authentication (<code>null</code> if no authentication is needed). 66 * @param proxyPass Password for basic authentication (<code>null</code> if no authentication is needed). 67 * @param requestHeaderLines An array with additional request header lines (without end-of-line markers) 68 * that have to be sent to the server. May be <code>null</code>. 69 */ 70 71 public HTTPProxyData(String proxyHost, int proxyPort, String proxyUser, String proxyPass, 72 String[] requestHeaderLines) 73 { 74 if (proxyHost == null) 75 throw new IllegalArgumentException("proxyHost must be non-null"); 76 77 if (proxyPort < 0) 78 throw new IllegalArgumentException("proxyPort must be non-negative"); 79 80 this.proxyHost = proxyHost; 81 this.proxyPort = proxyPort; 82 this.proxyUser = proxyUser; 83 this.proxyPass = proxyPass; 84 this.requestHeaderLines = requestHeaderLines; 85 } 86 } 87