kopia lustrzana https://github.com/JOSM/MapWithAI
Add User-Agent headers
Signed-off-by: Taylor Smock <smocktaylor@gmail.com>pull/1/head
rodzic
108b784900
commit
e5e7485d83
|
@ -1,6 +1,8 @@
|
||||||
// License: GPL. For details, see LICENSE file.
|
// License: GPL. For details, see LICENSE file.
|
||||||
package org.openstreetmap.josm.plugins.rapid.backend;
|
package org.openstreetmap.josm.plugins.rapid.backend;
|
||||||
|
|
||||||
|
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -24,6 +26,8 @@ import org.openstreetmap.josm.io.IllegalDataException;
|
||||||
import org.openstreetmap.josm.io.OsmReader;
|
import org.openstreetmap.josm.io.OsmReader;
|
||||||
import org.openstreetmap.josm.plugins.rapid.RapiDPlugin;
|
import org.openstreetmap.josm.plugins.rapid.RapiDPlugin;
|
||||||
import org.openstreetmap.josm.spi.preferences.Config;
|
import org.openstreetmap.josm.spi.preferences.Config;
|
||||||
|
import org.openstreetmap.josm.tools.HttpClient;
|
||||||
|
import org.openstreetmap.josm.tools.HttpClient.Response;
|
||||||
import org.openstreetmap.josm.tools.Logging;
|
import org.openstreetmap.josm.tools.Logging;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,10 +53,19 @@ public final class RapiDDataUtils {
|
||||||
String urlString = getRapiDURL();
|
String urlString = getRapiDURL();
|
||||||
try {
|
try {
|
||||||
final URL url = new URL(urlString.replace("{bbox}", bbox.toStringCSV(",")));
|
final URL url = new URL(urlString.replace("{bbox}", bbox.toStringCSV(",")));
|
||||||
Logging.debug("{0}: Getting {1}", RapiDPlugin.NAME, url.toString());
|
HttpClient client = HttpClient.create(url);
|
||||||
|
StringBuilder defaultUserAgent = new StringBuilder();
|
||||||
inputStream = url.openStream();
|
defaultUserAgent.append(client.getHeaders().get("User-Agent"));
|
||||||
|
if (defaultUserAgent.length() == 0) {
|
||||||
|
defaultUserAgent.append("JOSM");
|
||||||
|
}
|
||||||
|
defaultUserAgent.append(tr("/ {0} {1}", RapiDPlugin.NAME, RapiDPlugin.getVersionInfo()));
|
||||||
|
client.setHeader("User-Agent", defaultUserAgent.toString());
|
||||||
|
Logging.debug("{0}: Getting {1}", RapiDPlugin.NAME, client.getURL().toString());
|
||||||
|
Response response = client.connect();
|
||||||
|
inputStream = response.getContent();
|
||||||
dataSet.mergeFrom(OsmReader.parseDataSet(inputStream, null));
|
dataSet.mergeFrom(OsmReader.parseDataSet(inputStream, null));
|
||||||
|
response.disconnect();
|
||||||
} catch (UnsupportedOperationException | IllegalDataException | IOException e) {
|
} catch (UnsupportedOperationException | IllegalDataException | IOException e) {
|
||||||
Logging.debug(e);
|
Logging.debug(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Ładowanie…
Reference in New Issue