Skip to content

Commit

Permalink
Make FetchRequest not try and parse a 204 response body
Browse files Browse the repository at this point in the history
It currently checks for the presence of a Content-Type response header
and if present assumes that trying to parse the response will succeed.

Realtime currently sends a 204 (No Content) with a Content-Type header
from the POST rest.ably.io/push/publish endpoint when using HTTP 1.1
(see REA-1924).

(This bug hasn't been caught by the tests because I guess most of the
time they use HTTP 2 in browsers, and also we don't use FetchRequest in
the tests except briefly in those for the modular variant of the
library. I’ve created #1772 for improving this situation).

The 204 handling approach is copied from that which we already have in
XHRRequest.

Resolves #1771.
  • Loading branch information
lawrence-forooghian committed May 21, 2024
1 parent 50f0899 commit 80b6506
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/platform/web/lib/http/request/fetchrequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export default async function fetchRequest(

clearTimeout(timeout!);

if (res.status == 204) {
return { error: null, statusCode: res.status };
}

const contentType = res.headers.get('Content-Type');
let body;
if (contentType && contentType.indexOf('application/x-msgpack') > -1) {
Expand Down

0 comments on commit 80b6506

Please sign in to comment.