remm        01/07/24 23:14:35

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpClient.java HttpMethod.java HttpMethodBase.java
  Log:
  - Add preliminary proxy support.
    Patch submitted by Michael Smith <msmith at speedlegal.com>
  
  Revision  Changes    Path
  1.19      +47 -11    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java
  
  Index: HttpClient.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- HttpClient.java   2001/07/22 19:27:57     1.18
  +++ HttpClient.java   2001/07/25 06:14:34     1.19
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
 1.18 2001/07/22 19:27:57 remm Exp $
  - * $Revision: 1.18 $
  - * $Date: 2001/07/22 19:27:57 $
  + * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
 1.19 2001/07/25 06:14:34 remm Exp $
  + * $Revision: 1.19 $
  + * $Date: 2001/07/25 06:14:34 $
    *
    * ====================================================================
    *
  @@ -233,6 +233,18 @@
   
   
       /**
  +     * Proxy port number.
  +     */
  +    protected int proxyPort = -1;
  +
  +
  +    /**
  +     * Proxy hostname.
  +     */
  +    protected String proxyHost = null;
  +
  +
  +    /**
        * Port number.
        */
       protected int sessionPort = -1;
  @@ -733,6 +745,17 @@
   
   
       /**
  +     * Start a session with a proxy server.
  +     */
  +    public void startSession(String host, int port, 
  +                             String proxyhost, int proxyport) {
  +        this.proxyHost = proxyhost;
  +        this.proxyPort = proxyport;
  +        startSession(host, port);
  +    }
  +
  +
  +    /**
        * End a session.
        */
       public void endSession()
  @@ -758,14 +781,23 @@
   
           try {
               if (socket == null) {
  -                if (debug > 0)
  -                    System.out.println("Reopen connection : Host:"
  -                                       + sessionHost + " Port:" + sessionPort);
  -                if(https) {
  -                    socket = SSLSocketFactory.getDefault().createSocket
  -                        (this.sessionHost, this.sessionPort);
  +                if (proxyHost == null || proxyPort < 0) {
  +                    if (debug > 0)
  +                        System.out.println
  +                            ("Reopen connection : Host:"
  +                             + sessionHost + " Port:" + sessionPort);
  +                    if(https) {
  +                        socket = SSLSocketFactory.getDefault().createSocket
  +                            (this.sessionHost, this.sessionPort);
  +                    } else {
  +                        socket = new Socket
  +                            (this.sessionHost, this.sessionPort);
  +                    }
                   } else {
  -                    socket = new Socket(this.sessionHost, this.sessionPort);
  +                    if (debug > 0)
  +                        System.out.println("Reopen connection : Host:"
  +                                           + proxyHost + " Port:" + proxyPort);
  +                    socket = new Socket(this.proxyHost, this.proxyPort);
                   }
               }
               input = socket.getInputStream();
  @@ -836,7 +868,11 @@
   
           method.setState(state);
   
  -        String requestLine = method.generateRequestLine();
  +        String requestLine;
  +        if (proxyHost == null || proxyPort < 0)
  +            requestLine = method.generateRequestLine();
  +        else
  +            requestLine = method.generateRequestLine(getHost(), getPort());
   
           if (debug > 0) {
               System.out.println();
  
  
  
  1.4       +11 -3     
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java
  
  Index: HttpMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HttpMethod.java   2001/06/20 15:58:13     1.3
  +++ HttpMethod.java   2001/07/25 06:14:34     1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v
 1.3 2001/06/20 15:58:13 remm Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/06/20 15:58:13 $
  + * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v
 1.4 2001/07/25 06:14:34 remm Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/07/25 06:14:34 $
    *
    * ====================================================================
    *
  @@ -325,6 +325,14 @@
        * @return String request line
        */
       public String generateRequestLine();
  +
  +
  +    /**
  +     * Generate the HTTP request line, using a proxy server.
  +     *
  +     * @return String request line
  +     */
  +    public String generateRequestLine(String phost, int pport);
   
   
       /**
  
  
  
  1.9       +39 -3     
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HttpMethodBase.java       2001/07/19 00:44:53     1.8
  +++ HttpMethodBase.java       2001/07/25 06:14:34     1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
 1.8 2001/07/19 00:44:53 morgand Exp $
  - * $Revision: 1.8 $
  - * $Date: 2001/07/19 00:44:53 $
  + * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
 1.9 2001/07/25 06:14:34 remm Exp $
  + * $Revision: 1.9 $
  + * $Date: 2001/07/25 06:14:34 $
    *
    * ====================================================================
    *
  @@ -561,6 +561,42 @@
           }
   
           return (getName() + " " + requestString + " " + PROTOCOL + "\r\n");
  +
  +    }
  +
  +
  +    /**
  +     * Generate the HTTP request line, using proxy.
  +     *
  +     * @return String request line
  +     */
  +    public final String generateRequestLine(String phost, int pport) {
  +
  +        String requestString = state.URLEncode(path);
  +        if (queryString != null) {
  +            if (queryString.indexOf("?") < 0) {
  +                requestString += "?";
  +            }
  +            requestString += queryString;
  +        } else if (!parameters.isEmpty()) {
  +            // Parsing parameters list
  +            StringBuffer parametersString = new StringBuffer();
  +            Enumeration paramNames = parameters.keys();
  +            while (paramNames.hasMoreElements()) {
  +                String paramName = (String) paramNames.nextElement();
  +                String paramValue = (String) parameters.get(paramName);
  +                parametersString.append(state.URLEncode(paramName));
  +                parametersString.append("=");
  +                parametersString.append(state.URLEncode(paramValue));
  +                if (paramNames.hasMoreElements()) {
  +                    parametersString.append("&");
  +                }
  +            }
  +            requestString = requestString + "?" + parametersString.toString();
  +        }
  +
  +        return (getName() + " http://"; + phost + ":" + pport 
  +                + requestString + " " + PROTOCOL + "\r\n");
   
       }
   
  
  
  

Reply via email to