morgand     02/01/16 14:17:17

  Modified:    latka/src/java/org/apache/commons/latka/http
                        RequestImpl.java SessionImpl.java
  Log:
  fixed referer bug - Latka will now set the correct referer in a Session when
  HTTPClient follows a 301 or 302 redirect
  
  Revision  Changes    Path
  1.15      +9 -0      
jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestImpl.java
  
  Index: RequestImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- RequestImpl.java  10 Oct 2001 20:57:30 -0000      1.14
  +++ RequestImpl.java  16 Jan 2002 22:17:17 -0000      1.15
  @@ -188,6 +188,15 @@
         
         response = new ResponseImpl(this);
   
  +      // set the referer
  +      // note: If followRedirects
  +      // is enabled, HTTPClient may return a path
  +      // that is different from the initial request.
  +      // HTTPClient will not follow redirects to another
  +      // host or port; in that event, it will always
  +      // return a 301 or 302.
  +      _session.setReferer(new 
URL(_targetURL.getProtocol(),_host,_port,_httpMethod.getPath()));
  +
       } catch (IOException e) {
         // rethrow it after closing the connection
         throw e;
  
  
  
  1.8       +30 -3     
jakarta-commons/latka/src/java/org/apache/commons/latka/http/SessionImpl.java
  
  Index: SessionImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/SessionImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SessionImpl.java  10 Oct 2001 20:57:58 -0000      1.7
  +++ SessionImpl.java  16 Jan 2002 22:17:17 -0000      1.8
  @@ -123,13 +123,40 @@
       RequestImpl request = 
         new RequestImpl(label,url, httpMethod, _state, this, followRedirects);
   
  -    if (_urls.size() > 0) {
  -      request.setHeader("Referer", ((URL)_urls.getLast()).toString());
  +    URL referer = getReferer();
  +
  +    if (referer != null) {
  +      request.setHeader("Referer", referer.toString());
       }
   
  +    return request;
  +  }
  +
  +  /**
  +   * Called inside the request.execute() method, setting the
  +   * referer for the next request.
  +   * 
  +   * @param url    URL of the last executed request.
  +   */
  +  protected void setReferer(URL url) {
       _urls.add(url);
  +  }
   
  -    return request;
  +  /**
  +   * The URL of the last request that was executed.  This
  +   * will be the _actual_ url accessed in the result of 
  +   * a 301 or 302 redirect (the page that returned
  +   * a 200 status code).
  +   * 
  +   * @return Referer of the last request, or null if there have
  +   *         been no successful requests.
  +   */
  +  protected URL getReferer() {
  +    if (_urls.size() > 0) {
  +      return (URL)_urls.getLast();
  +    }
  +
  +    return null;
     }
   
     /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to