Menu

#194 refresh metatag redirects immediately

closed
nobody
None
5
2012-10-21
2005-01-06
yhal003
No

code:
public static void main(String[] args) {
try{
final String url = "http://localhost:8080/Hello.html";
final WebClient client = new WebClient();
HtmlPage page = (HtmlPage)client.getPage(new URL(url));
System.out.println(page.asText());
}
catch(Exception ex){}
}

with html pages:
Hello.html

<meta http-equiv="Refresh" content="500000;url=/redirect.html"> hello

redirect.html

redirect

when it runs I get page = redirect.html and Hello.html
is "lost"
althought redirect should follow after 50000 sec;
is that bug?

Discussion

  • Brad Clarke

    Brad Clarke - 2005-01-06

    Logged In: YES
    user_id=257129

    meta redirects are processed immediately but this should
    probably be an optiona thing

     
  • Daniel Gredler

    Daniel Gredler - 2005-01-27

    Logged In: YES
    user_id=1109422

    According to every page I've seen (for example,
    http://www.htmlhelp.com/reference/html40/head/meta.html),
    you're supposed to be able to specify the time to wait in
    seconds. I think HtmlUnit's behavior is flat out incorrect
    in executing the refresh immediately.

    I've been looking in the code, and don't really understand
    the need for RefreshHandler and DefaultRefreshHandler. Why
    would someone want to implement a custom RefreshHandler? Why
    does DefaultRefreshHandler ignore the timeBeforeRefresh
    parameter? The JavaDocs for these handlers mention that
    refreshes can be triggered via JavaScript, but the handlers
    are only used for refreshes triggered via response headers
    or meta tags. Can the refresh handlers be taken out?

     
  • yhal003

    yhal003 - 2005-01-27

    Logged In: YES
    user_id=1191274

    Well that is what I did to resolve that issue - implemented
    Refresh handler so that it never redirects-

    package com.gargoylesoftware.htmlunit;
    import java.net.URL;

    public class FakeHandler implements RefreshHandler{
    public boolean shouldRefresh(Page page,URL url,int integer){
    return false;
    }
    }

    and then assigned it to the client:

    client.setRefreshHandler(new FakeHandler());

     
  • Marc Guillemot

    Marc Guillemot - 2005-02-11

    Logged In: YES
    user_id=402164

    I'm not the author of the refersh handler related code but I
    understand the implemenation: it is simple and safe.
    Waiting for the indicated delay would require to start a
    separate thread that would perform the refresh after the
    indicated time. In the meantime, it should be possible to
    manipulate the page containing the <meta refresh="">, and
    during this manipulation, the page could "lose its window".
    If the javadoc is wrong, then it should be fixed.
    I think that it is usefull to have the possibility to
    specify the way refresh should be performed: in most cases
    an immediate refresh allows tests to run faster, but
    sometime the business logic requires to wait for the
    specified time. Optimal would be to give the possibility to
    work like browsers do as well, taking care of the problems
    I've mentionned before.

    Perhaps could it be convenient to provide some
    RefreshHandler instances:

    • a "no refresh" RefeshHandler excactly like yha1003's
      FakeHandler dismissing refresh requests.
    • a "wait refresh" RefreshHandler performing a wait for the
      time.

    I think that this bug can be closed. Please reopen if it is
    not the case.

     

Log in to post a comment.

MongoDB Logo MongoDB