react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

When 'Content MD5' is passed in the headers during a fetch request, it will cause the request to fail

Open ShaoGongBra opened this issue 2 years ago • 4 comments

Problem Description

fetch('https://dpfb.yixunshop.com/api/screen/auth', {
    method: 'POST',
    body: "{\"no\":\"\",\"username\":\"\",\"password\":\"\"}",
    headers: {
      Accept: "application/json",
      AccessKey: "81506876",
      'Content-Date': "1700879664",
      // When 'Content MD5' is passed in the headers, it will cause the request to fail
      'Content-MD5': "a82322fb6d03879e296243bc55867dce2b72644c0aeaf9829a42ce18af5d8b0e",
      'Content-Type': "application/json"
    }
  }).then(async res => {
    console.log('res', await res.text())
  }).catch(err => {
    console.log('err', err)
    // err TypeError: Network request failed
  })

Steps To Reproduce

fetch request

Expected Results

No response

CLI version

0.72.6

Environment

System:
  OS: Windows 11 10.0.22631
  CPU: (16) x64 Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
  Memory: 6.77 GB / 15.87 GB
Binaries:
  Node:
    version: 18.18.2
    path: ~\AppData\Local\Temp\yarn--1700880356341-0.3000326603832264\node.CMD
  Yarn:
    version: 1.22.19
    path: ~\AppData\Local\Temp\yarn--1700880356341-0.3000326603832264\yarn.CMD
  npm:
    version: 9.8.1
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    AllowAllTrustedApps: Enabled
IDEs:
  Android Studio: AI-223.8836.35.2231.11005911
  Visual Studio:
    - 17.8.34316.72 (Visual Studio Community 2022)
Languages:
  Java:
    version: 11.0.21
    path: C:\Program Files\Common Files\Oracle\Java\javapath\javac.EXE
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.7
    wanted: ^0.72.6
  react-native-windows:
    installed: 0.72.20
    wanted: 0.72.20
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Target Platform Version

None

Target Device(s)

No response

Visual Studio Version

None

Build Configuration

None

Snack, code example, screenshot, or link to a repository

No response

ShaoGongBra avatar Nov 25 '23 02:11 ShaoGongBra

There's custom handling for the known parts of the headers, but I thought the rest were passed through as a property bag. @JunielKatarn is that accurate? Is there any handling specific to Content-MD5? Is there a validation failure that could happen and we should use the unvalidated passthrough?

chrisglein avatar Nov 27 '23 18:11 chrisglein

Is there any progress on this issue

ShaoGongBra avatar Dec 03 '23 13:12 ShaoGongBra

Investigation has not yet started. Will look into this issue next week.

JunielKatarn avatar Dec 09 '23 01:12 JunielKatarn

Are you making progress

ShaoGongBra avatar Jan 18 '24 08:01 ShaoGongBra

I have reproduced this issue locally. Looking for the root cause...

JunielKatarn avatar May 15 '24 20:05 JunielKatarn

The underlying Windows networking stack (WinInet) is throwing this error. It's possible this stack does not support manually setting the Content-MD5 header.

[0x8000000e] Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.

JunielKatarn avatar May 15 '24 20:05 JunielKatarn

We will compare this behavior against other React Native variants (iOS, Android...). If those accept this header combination, we will relax validation for Content- headers.

JunielKatarn avatar May 17 '24 22:05 JunielKatarn