Graylog2 / graylog2-server

Free and open log management
https://www.graylog.org
Other
7.33k stars 1.06k forks source link

ContentPack download from the list of ContentPacks does not work during dev on localhost #10548

Closed janheise closed 3 years ago

janheise commented 3 years ago

Expected Behavior

When you select "more actions"->"download" next to a ContentPack, you should be able to download the JSON using the "Save link as" option from the context menu on the link in the popup.

Current Behavior

"Save link as" does not work during development.

Steps to Reproduce (for bugs)

  1. Select "Content Packs" from the "System" Menu
  2. Select "more actions" on the right for any Content Pack
  3. Select "download"
  4. try to follow the download instructions in the Popup

Context

As a developer, this is needed to check download/installation of ContentPacks

Your Environment

bernd commented 3 years ago

I can reproduce that. This would fix it, not sure if that's the right way, though. :wink: /cc @dennisoelkers @kmerz @linuspahl

diff --git graylog2-web-interface/src/components/content-packs/ContentPackDownloadControl.jsx graylog2-web-interface/src/components/content-packs/ContentPackDownloadControl.jsx
index 4619780dac..36b05087b8 100644
--- graylog2-web-interface/src/components/content-packs/ContentPackDownloadControl.jsx
+++ graylog2-web-interface/src/components/content-packs/ContentPackDownloadControl.jsx
@@ -42,11 +42,15 @@ class ContentPackDownloadControl extends React.Component {
   _getDownloadUrl() {
     const { contentPackId, revision } = this.props;

-    const url = new URI(URLUtils.qualifyUrl(
+    let url = new URI(URLUtils.qualifyUrl(
       ApiRoutes.ContentPacksController.downloadRev(contentPackId, revision).url,
     ));

     if (URLUtils.areCredentialsInURLSupported()) {
+      // If we set username and password for a relative URL, we get a broken link. (e.g. "username:password@/api/...")
+      if (url.is('relative')) {
+        url = url.absoluteTo(location.href);
+      }
       url
         .username(SessionStore.getSessionId())
         .password('session');