Fetch of mp3 succeeds but with http status zero not 200

using capacitor 6.2, deploying via xcode to ios device.

A simple fetch for a local resource such as

fetch("/public/C4.mp3", { method: "GET" });

produces a result with http status 0 instead of 200. The fetch succeeds, as I can get the full data stream, but the incorrect status code is a problem when a library is doing the fetching.

renaming the file to extension “.mpthree” addresses the issue.

What’s special about mp3?
What other types will have this issue?
Is (isn’t?) it a bug to produce http result code zero?

Are you using Capacitor HTTP where it is intercepting your fetch calls?

Also, why are you fetching the mp3 instead of just using a normal HTTP path?

Not using the capacitor http package. That said, I see from network inspection that my request is processed as “capacitor://localhost/C4.mp3”. It’s my understanding that it works that way regardless of using the http package.

I don’t understand your second question regarding why fetch vs normal http path. I need the content of the mp3, as it provides a sound sample that I must process.

You can disregard my second question since you are trying to get the actual bytes of the file for further processing. As a workaround, maybe just store the byte array of the mp3 directly in your JS? :smile:

I believe Capacitor still intercepts calls to see if they should be handled by the virtual web server serving your Capacitor app or by an external web server. WebViewAssetHandler.swift seems to be the class that handles loading assets in Capacitor.

Have you checked the XCode logs to see if there are any errors from Capacitor?

It does sound like a bug. Hopefully someone from the Capacitor team can chime in.

Thanks. I was just looking at WebViewAssetHandler.swift. Here’s what I determined:

Various file extensions, including mp3, are identified as media files (function IsMediaExtension

If it’s a media extension AND there is a range header, range processing is done, and the response is a HTTPUrlResponse with HTTP status 206.

else if it’s a media extension, a UrlReponse (not the subclass HTTPUrlResponse) is returned. UrlReponse doesn’t have a http status property. (see lines 89-95)

That looks very intentional, but seems wrong. Why should my http request not return a http status?

Anyway, I’ll work around the problem by naming my files .mpthree.

thanks for the responses.