Index: trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java	(revision 13871)
+++ trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java	(revision 13872)
@@ -167,5 +167,5 @@
         try {
             CheckParameterUtil.ensureThat(ImageryType.WMS_ENDPOINT.equals(info.getImageryType()), "wms_endpoint imagery type expected");
-            final WMSImagery wms = new WMSImagery(info.getUrl());
+            final WMSImagery wms = new WMSImagery(info.getUrl(), info.getCustomHttpHeaders());
 
             final WMSLayerTree tree = new WMSLayerTree();
@@ -201,12 +201,10 @@
                     .map(LayerDetails::getName)
                     .collect(Collectors.joining(", "));
-            ImageryInfo ret = new ImageryInfo(info.getName() + selectedLayers,
-                    url,
-                    "wms",
-                    info.getEulaAcceptanceRequired(),
-                    info.getCookies());
-
+            // Use full copy of original Imagery info to copy all attributes. Only overwrite what's different
+            ImageryInfo ret = new ImageryInfo(info);
+            ret.setUrl(url);
+            ret.setImageryType(ImageryType.WMS);
+            ret.setName(info.getName() + selectedLayers);
             ret.setServerProjections(wms.getServerProjections(tree.getSelectedLayers()));
-
             return ret;
         } catch (MalformedURLException ex) {
Index: trunk/src/org/openstreetmap/josm/data/imagery/WMSEndpointTileSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/WMSEndpointTileSource.java	(revision 13871)
+++ trunk/src/org/openstreetmap/josm/data/imagery/WMSEndpointTileSource.java	(revision 13872)
@@ -43,5 +43,5 @@
         CheckParameterUtil.ensure(info, "imageryType", x -> ImageryType.WMS_ENDPOINT.equals(x.getImageryType()));
         try {
-            wmsi = new WMSImagery(info.getUrl());
+            wmsi = new WMSImagery(info.getUrl(), info.getCustomHttpHeaders());
         } catch (IOException | WMSGetCapabilitiesException e) {
             throw new IllegalArgumentException(e);
Index: trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java	(revision 13871)
+++ trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java	(revision 13872)
@@ -432,5 +432,9 @@
                         // TODO should we handle also POST?
                         if ("GET".equalsIgnoreCase(mode) && getMapUrl != null && !"".equals(getMapUrl)) {
-                            this.getMapUrl = getMapUrl;
+                            if (getMapUrl.endsWith("?")) {
+                                this.getMapUrl = getMapUrl;
+                            } else {
+                                this.getMapUrl = getMapUrl + "?";
+                            }
                         }
                     }
Index: trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java	(revision 13871)
+++ trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java	(revision 13872)
@@ -8,8 +8,10 @@
 import java.util.Arrays;
 
+import org.fest.util.Collections;
 import org.junit.Rule;
 import org.junit.Test;
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.TestUtils;
+import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
 import org.openstreetmap.josm.data.projection.Projections;
 import org.openstreetmap.josm.spi.preferences.Config;
@@ -83,3 +85,63 @@
                 + "BBOX=20037506.6204108,-60112521.5836107,60112521.5836107,-20037506.6204108", tileSource.getTileUrl(1, 1, 1));
     }
+
+    @Test
+    public void testCustomHeaders() throws Exception {
+        tileServer.stubFor(
+                WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
+                .willReturn(
+                        WireMock.aResponse()
+                        .withBody(Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/webatlas.no.xml")))
+                        )
+                );
+
+        tileServer.stubFor(WireMock.get(WireMock.urlEqualTo("//maps")).willReturn(WireMock.aResponse().withBody(
+                "<?xml version='1.0' encoding='UTF-8'?>\n" +
+                "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" +
+                "  <entry>\n" +
+                "        <name>Norway Orthophoto (historic)</name>\n" +
+                "        <name lang=\"nb\">Norge i Bilder (historisk)</name>\n" +
+                "        <id>geovekst-nib-historic</id>\n" +
+                "        <type>wms_endpoint</type>\n" +
+                "        <country-code>NO</country-code>\n" +
+                "        <description lang=\"en\">Historic Norwegian orthophotos and maps, courtesy of Geovekst and Norkart.</description>\n" +
+                "        <url><![CDATA[" + tileServer.url("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities") + "]]></url>\n" +
+                "        <custom-http-header header-name=\"X-WAAPI-TOKEN\" header-value=\"b8e36d51-119a-423b-b156-d744d54123d5\" />\n" +
+                "        <attribution-text>© Geovekst</attribution-text>\n" +
+                "        <attribution-url>https://www.norgeibilder.no/</attribution-url>\n" +
+                "        <permission-ref>https://forum.openstreetmap.org/viewtopic.php?id=62083</permission-ref>\n" +
+                "        <icon>https://register.geonorge.no/data/organizations/_L_norgeibilder96x96.png</icon>\n" +
+                "        <max-zoom>21</max-zoom>\n" +
+                "        <valid-georeference>true</valid-georeference>\n" +
+                "</entry>\n" +
+                "</imagery>"
+                )));
+
+        Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
+        ImageryLayerInfo.instance.loadDefaults(true, null, false);
+        ImageryInfo wmsImageryInfo = ImageryLayerInfo.instance.getDefaultLayers().get(0);
+        wmsImageryInfo.setDefaultLayers(Collections.list(new DefaultLayer(ImageryType.WMS_ENDPOINT, "historiske-ortofoto", "", "")));
+        WMSEndpointTileSource tileSource = new WMSEndpointTileSource(wmsImageryInfo, Main.getProjection());
+        tileSource.initProjection(Projections.getProjectionByCode("EPSG:3857"));
+        assertEquals("b8e36d51-119a-423b-b156-d744d54123d5", wmsImageryInfo.getCustomHttpHeaders().get("X-WAAPI-TOKEN"));
+        assertEquals("b8e36d51-119a-423b-b156-d744d54123d5", tileSource.getHeaders().get("X-WAAPI-TOKEN"));
+        assertEquals(true, wmsImageryInfo.isGeoreferenceValid());
+        tileServer.verify(
+                WireMock.getRequestedFor(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
+                .withHeader("X-WAAPI-TOKEN", WireMock.equalTo("b8e36d51-119a-423b-b156-d744d54123d5")));
+        assertEquals("http://waapi.webatlas.no/wms-orto-hist/?"
+                + "FORMAT=image/png&"
+                + "TRANSPARENT=TRUE&"
+                + "VERSION=1.1.1&"
+                + "SERVICE=WMS&"
+                + "REQUEST=GetMap&"
+                + "LAYERS=historiske-ortofoto&"
+                + "STYLES=&"
+                + "SRS=EPSG:3857&"
+                + "WIDTH=512&"
+                + "HEIGHT=512&"
+                + "BBOX=20037506.6204108,-60112521.5836107,60112521.5836107,-20037506.6204108",
+                tileSource.getTileUrl(1, 1, 1));
+
+    }
 }
