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

QNAM cannot get response from Qt HTTP Server due to WASM app not being allowed to perform Cross-Origin Resource Sharing

    XMLWordPrintable

Details

    • WebAssembly

    Description

      One can use "Simple HTTP Server" (Qt\Examples\Qt-6.8.2\httpserver\simple) and "HTTP Client" (Qt\Examples\Qt-6.8.2\network\http) examples to confirm the behavior.

      On desktop, everything is fine. Client can receive and handle response from server perfectly. Not so much if the client is built and run as a WASM application. Client always fails due to error 399, i.e. QNetworkReply::ProtocolFailure, when trying to get response from server. On the other hand, browser itself has no such problem.

      The reason is that it seems like Cross-Origin Resource Sharing is not allowed. For the response returned by QHttpServer, such header has to be added to make WASM client work (maybe not all of the entries are needed but including all of them certainly works):

              QHttpHeaders header;
              header.append("Allow", "*");
              header.append("Access-Control-Allow-Origin", "*");
              header.append("Access-Control-Allow-Language", "*");
              header.append("Access-Control-Allow-Encoding", "*");
              header.append("Access-Control-Allow-Method", "*");
              header.append("Access-Control-Allow-Headers", "*");
              res.setHeaders(header);
      

      Not sure if it is by design or user is expected to manually enable resource sharing like that.

      Attachments

        For Gerrit Dashboard: QTBUG-133462
        # Subject Branch Project Status CR V

        Activity

          People

            lopotter-ext Lorn Potter
            luqiaochen Luqiao Chen
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change