Ticket #3580: auth.patch

File auth.patch, 2.2 KB (added by bastiK, 15 years ago)

Don't send authorisation for "GET / capabilities" requests.

  • src/org/openstreetmap/josm/io/OsmApi.java

     
    162162        cancel = false;
    163163        initAuthentication();
    164164        try {
    165             String s = sendRequest("GET", "capabilities", null,monitor);
     165            String s = sendRequest("GET", "capabilities", null,monitor, false);
    166166            InputSource inputSource = new InputSource(new StringReader(s));
    167167            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser());
    168168            if (capabilities.supportsVersion("0.6")) {
     
    458458        return Math.max(ret,0);
    459459    }
    460460
     461    private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor) throws OsmTransferException {
     462        return sendRequest(requestMethod, urlSuffix, requestBody, monitor, true);
     463    }
     464
    461465    /**
    462466     * Generic method for sending requests to the OSM API.
    463467     *
     
    473477     * @exception OsmTransferException if the HTTP return code was not 200 (and retries have
    474478     *    been exhausted), or rewrapping a Java exception.
    475479     */
    476     private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor) throws OsmTransferException {
     480    private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor, boolean doAuthenticate) throws OsmTransferException {
    477481        StringBuffer responseBody = new StringBuffer();
    478 
    479482        int retries = getMaxRetries();
    480483
    481484        while(true) { // the retry loop
     
    485488                activeConnection = (HttpURLConnection)url.openConnection();
    486489                activeConnection.setConnectTimeout(15000);
    487490                activeConnection.setRequestMethod(requestMethod);
    488                 addAuth(activeConnection);
     491                if (doAuthenticate) {
     492                    addAuth(activeConnection);
     493                }
    489494
    490495                if (requestMethod.equals("PUT") || requestMethod.equals("POST") || requestMethod.equals("DELETE")) {
    491496                    activeConnection.setDoOutput(true);