Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-125280

QGeoTileFetcherOsm::getTileImage shouldn't set UserAgent for WebAssembly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.7.0
    • Location
    • None
    • WebAssembly

    Description

      I'm using Qt Location OSM maps on the WebAssembly target, which is mostly working after applying this patch https://bugreports.qt.io/browse/QTBUG-124111 and setting osm.mapping.providersrepository.address to a server that supports https.

      However, there is what appears to be a small problem in QGeoTileFetcherOsm::getTileImage, in that it sets the UserAgent header.

      In Chrome/Edge, this is a minor issue. For every tile fetch, we get a message in the log:

      Refused to set unsafe header "User-Agent".
      

      And it sends the GET request with it's normal Mozilla User-Agent header, ignoring what was set.

      In Firefox, it's more problematic, as instead of replacing it, it sends a preflight request to the tile server. Some tile servers (E.g. cartocdn) do-not return CORS headers on preflight responses, which results in Firefox blocking the subsequent GET request. If we don't set this User-Agent header, then Firefox doesn't do the preflight, and just sends the GET request with User-Agent set to Mozilla, which then successfully returns the image tile.

      So, to work around the problem, it seems we can just not set the header in getTileImage on WebAssembly. E.g:

          QNetworkRequest request;
      #ifndef __EMSCRIPTEN__
          // Don't set UserAgent header for Emscripten
          // Chrome logs: Refused to set unsafe header "User-Agent" and sets it to Mozilla anyway
          // Firefox sends an OPTIONS preflight, and some tile servers don't return Access-Control-Allow-Origin headers for these
          // resulting in GET being blocked by Firefox. If we don't set it, Firefox uses Mozilla
          request.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent);
      #endif    
          request.setUrl(url);
          QNetworkReply *reply = m_nm->get(request);
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            piwierci Piotr WierciƄski
            srcejon Jon Beniston
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes