Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] problems with reading images with proxy_pass #37

Open
eximius313 opened this issue Feb 21, 2019 · 0 comments
Open

[BUG] problems with reading images with proxy_pass #37

eximius313 opened this issue Feb 21, 2019 · 0 comments

Comments

@eximius313
Copy link
Contributor

eximius313 commented Feb 21, 2019

Let's say we have a template:

<html>
<head>
  <meta charset="UTF-8">
  <title>my title</title>
</head>
<body>
<div class="photo"
      style="background-image: url('@routes.ImageController.myPicture("funnyCat")')"></div>
</body>
</html>

and we use it like this:

  public Result preparePdf() {
    final String host = routes.HomeController.index().absoluteURL(request());
    return ok(pdfGenerator.toBytes(views.html.myPdf.render(), host))
        .withHeader("Content-Disposition", "attachment; filename*=UTF-8''My.pdf")
        .as("application/pdf");
  }

and - what is important - our application.conf looks like this:

play {
  http {
    secret.key="secret_here"
    hostname = "myhost.io"
  }
  filters {
    enabled=[play.filters.hosts.AllowedHostsFilter]
    hosts.allowed=["myhost.io"]
  }
}

If you run stage locally - everything works fine and photos are displayed in PDF.
BUT if you are running your server with Apache mod_proxy:

    ProxyRequests Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode

    ProxyPass           /               http://localhost:9009/  nocanon
    ProxyPassReverse    /               http://localhost:9009/

then even if: final String host = routes.HomeController.index().absoluteURL(request()); points correctly to https://myhost.io, PDF is generated but no photos are displayed, nor exception is thrown.
It just fails silently!

Workaround that I found after hours of investigation is that you must use http://localhost:9009 for both:

//    final String host = routes.HomeController.index().absoluteURL(request());
    final String host = "http://localhost:9009";

and

  filters {
    enabled=[play.filters.hosts.AllowedHostsFilter]
    hosts.allowed=["myhost.io", "localhost:9009"]
  }

Why play2-pdf reads photos from localhost:9009 even though I'm pointing it specifically to myhost.io?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant