Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.post sending no Content-Length #42369

Closed
deakjahn opened this issue Jun 10, 2020 · 3 comments
Closed

http.post sending no Content-Length #42369

deakjahn opened this issue Jun 10, 2020 · 3 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@deakjahn
Copy link

Steps to Reproduce

The following code:

final response = await http.post(url,
  headers: {
    'Content-Type': 'application/octet-stream',
    'Content-Length': (await fileSize(file)).toString(),
  },
  body: await fileRead(file));

(URL actually being the Google Cloud like https://www.googleapis.com/upload/storage/... returns the following error on Android:

411 Length Required

fileSize() reads the file size, fileRead() returns the content as an Uint8List. They both work all right. And yes, using the lower level approach with these calls:

final http = HttpClient();
final request = await http.postUrl(Uri.parse(url));
request.headers.set('Content-Type', 'application/octet-stream');
request.headers.set('Content-Length', await fileSize(file));
request.add(await fileRead(file));
final response = await request.close();
http.close();

works.

Doc
[√] Flutter (Channel beta, 1.18.0-11.1.pre, on Microsoft Windows [Version 10.0.18363.836], locale en-US)
    • Flutter version 1.18.0-11.1.pre at E:\Android\flutter-beta
    • Framework revision 2738a1148b (4 weeks ago), 2020-05-13 15:24:36 -0700
    • Engine revision ef9215ceb2
    • Dart version 2.9.0 (build 2.9.0-8.2.beta)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
    • Android SDK at e:\Android\Sdk
    • Platform android-29, build-tools 29.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • CHROME_EXECUTABLE = e:\Android\chrome.bat

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 46.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (2 available)
    • Web Server • web-server • web-javascript • Flutter Tools
    • Chrome     • chrome     • web-javascript • Google Chrome 83.0.4103.97

• No issues found!
@zichangg
Copy link
Contributor

@deakjahn Thanks for filing the issue. I think this is a dart:io issue. I'll transfer to SDK and work on a fix.

@zichangg zichangg transferred this issue from dart-lang/http Jun 17, 2020
@zichangg zichangg self-assigned this Jun 17, 2020
@deakjahn
Copy link
Author

Just make sure that the fix works in both mobile and Flutter Web. :-)

@mraleph mraleph added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io labels Jun 17, 2020
@sortie sortie added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jun 17, 2020
dart-bot pushed a commit that referenced this issue Jun 19, 2020
If the Content-Length has been set by contentLength setter, manually
setting the header to the same value will lead to the header being
dropped, since _contentLength is not updated in set() method. The method
set() will erase the header and add back the header with new value. As
_contentLength is not updated, when it adds back the new header, it
looks at _contentLength (Which is not reset) and skips the addition (
_contentLength is the same as the new value, we had the header already).

Bug: #42369
Change-Id: I3fba7cc332bdff0ba56e602ac810fbaeb85d2606
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151427
Commit-Queue: Zichang Guo <zichangguo@google.com>
Reviewed-by: Jonas Termansen <sortie@google.com>
@sortie
Copy link
Contributor

sortie commented Jul 1, 2020

Closing since this is supposed to be fixed in 242ce27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants