Skip to content

Remove Content-Length header from proxy inspector response#42590

Closed
kmagiera wants to merge 1 commit into
facebook:mainfrom
kmagiera:patch-2
Closed

Remove Content-Length header from proxy inspector response#42590
kmagiera wants to merge 1 commit into
facebook:mainfrom
kmagiera:patch-2

Conversation

@kmagiera
Copy link
Copy Markdown
Contributor

Summary:

This change removes Content-Length header from proxy inspector response.

The presence of this header was resulting in the response being cropped under some circumstances because of erroneously calculated length.

The Content-Length header value represents the number of bytes in the response. In the code, string.length was used to calculate that value, but in JavaScript it gives the number of characters in a string instead of its size in bytes. Specifically, if there are some UTF characters in the string that occupy more than byte, there would be a mismatch in this size. This mismatch resulted in the response being cropped.

The easiest way to reproduce this problem is to set the simulator name to contain a two-byte UTF character.

This change works according to the HTTP spec, which states that when Content-Length is not present, the end of the response stream indicates the end of the response. Since in the code response.end(data) is use, it terminates the stream and hence there is no need to provide the length in the header.

Changelog:

[GENERAL] [FIXED] - fix issue with debugger not working when device name contain two-byte UTF characters

Test Plan:

  1. Change your iOS simulator name to contain some two-byte UTF character (for example this one: "–")
  2. Run metro and connect your app with it
  3. Go to http://localhost:8081/json/list in your browser – see the response being marked invalid as it is cropped
  4. Apply the change and see that the resulting JSON in the response is now correct
  5. Open debugger workflow to confirm it sees the connected device

This change removes Content-Length header from proxy inspector response.

This header was resulting in the response being cropped some times, because of erroneously calculated langth. The Content-Length value represents the number of bytes in the response while string.length was used to calculate the value, which gives the number of characters in a string instead of its size in bytes. Specifically, if there are some UTF characters in the string that occupy more than byte, there would be a mismatch in this size which resulted in the response being cropped. This could happen for example when the simulator name contains such character.
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jan 22, 2024
@motiz88
Copy link
Copy Markdown
Contributor

motiz88 commented Jan 22, 2024

Thanks @kmagiera, appreciate the fix!

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@motiz88 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jan 22, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@motiz88 merged this pull request in d16531e.

kmagiera added a commit to software-mansion/radon-ide that referenced this pull request Mar 19, 2024
With Expo 50, we no longer can you same metro runner as they've landed
several changes that just breaks with the way we'd set up packager.

This PR makes it so that we use similar path to starting packager with
`expo start`.

Here is what's changed:
1. When project has app.json, we use new expo start way of launching the
packager
2. We extracted a number of metro related code to separate lib file such
that it can be used both by old metro config and by expo setup
3. We blacklisted more jsx-transform modules, as they started
conflicting with different setups
4. We're removing – (hyphen) char from default device names, as they
started to cause issues with debugger (see
facebook/react-native#42590)
5. Expo metro setup now has a new expo_start script that uses some
internal method overrides in order to inject code that updates metro
config
6. The expo setup is configured as CI such that it doesn't print too
much formatted output
7. We also had to override package that tests for a busy port, because
it didn't handle port nr 0 well
8. Finally we made small adjustments in runtime code in order to load
lazily some internal RN modules
9. Also some small adjustments were made in the code controlling metro
process such that it handles metro crashes and outputs some important
messages better
Apple0717 added a commit to Apple0717/radon that referenced this pull request Nov 30, 2024
With Expo 50, we no longer can you same metro runner as they've landed
several changes that just breaks with the way we'd set up packager.

This PR makes it so that we use similar path to starting packager with
`expo start`.

Here is what's changed:
1. When project has app.json, we use new expo start way of launching the
packager
2. We extracted a number of metro related code to separate lib file such
that it can be used both by old metro config and by expo setup
3. We blacklisted more jsx-transform modules, as they started
conflicting with different setups
4. We're removing – (hyphen) char from default device names, as they
started to cause issues with debugger (see
facebook/react-native#42590)
5. Expo metro setup now has a new expo_start script that uses some
internal method overrides in order to inject code that updates metro
config
6. The expo setup is configured as CI such that it doesn't print too
much formatted output
7. We also had to override package that tests for a busy port, because
it didn't handle port nr 0 well
8. Finally we made small adjustments in runtime code in order to load
lazily some internal RN modules
9. Also some small adjustments were made in the code controlling metro
process such that it handles metro crashes and outputs some important
messages better
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Software Mansion Partner: Software Mansion Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants