Moddable-OpenSource / moddable

Tools for developers to create truly open IoT products using standard JavaScript on low cost microcontrollers.
http://www.moddable.com
1.34k stars 237 forks source link

fetch fails when `content-length` and "transfer-encoding" are not set. #1381

Closed stc1988 closed 3 months ago

stc1988 commented 3 months ago

Build environment: mac Moddable SDK version: 3fe65e9 Target device: macOS simulator

Steps to Reproduce

  1. Build and install the fetch example app using this build command: mcconfig -d -m -p mac
  2. See error /Users/satoshi/Projects/moddable/examples/io/tcp/fetch/fetch.js (206) # Break: (anonymous-104): cannot coerce undefined to object!

Other information

This issue seems to occur in the case of recent commit and the conditions mentioned in the title.

phoddie commented 3 months ago

Thank you for the report. Yes, this problem was introduced with the recent change. Fortunately, the fix is simple. Change the line that fails from if (transferEncoding.toLowerCase() != "chunked") to if (transferEncoding?.toLowerCase() != "chunked").

stc1988 commented 3 months ago

Change the line that fails from if (transferEncoding.toLowerCase() != "chunked") to if (transferEncoding?.toLowerCase() != "chunked").

Thank you. This change makes app works.

stc1988 commented 3 months ago

I confirmed this fixed. Thank you.