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

Connection closed before full header was received #48450

Closed
chengqing97 opened this issue Feb 22, 2022 · 3 comments
Closed

Connection closed before full header was received #48450

chengqing97 opened this issue Feb 22, 2022 · 3 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io

Comments

@chengqing97
Copy link

chengqing97 commented Feb 22, 2022

Issue:

I am getting this error when sending requests to some URLs:

Unhandled exception:
HttpException: Connection closed before full header was received, uri = https://dictionary.cambridge.org/dictionary/english/hello

My environment:

Dart: Dart SDK version: 2.16.1 (stable) on "linux_x64"
OS: Debian 11 bullseye
Kernel: x86_64 Linux 5.10.0-11-amd64

Steps to reproduce:

  1. Create a main.dart
  2. Inside main.dart:
import 'dart:convert';
import 'dart:io';

void main(List<String> arguments) async {
  final url1 = Uri.parse("https://dictionary.cambridge.org/dictionary/english/hello");
  final url2 = Uri.parse("https://dict.youdao.com/w/hello");

  var client = HttpClient();
  try {
    HttpClientRequest request = await client.getUrl(url1);
    HttpClientResponse response = await request.close();
    final stringData = await response.transform(utf8.decoder).join();
    print(stringData);
  } finally {
    client.close();
  }
}

  1. Run the code dart run main.dart

I can make request to url2 just fine. I'm only getting error when making request to url1

@ghost
Copy link

ghost commented Feb 22, 2022

Probably a duplicate of flutter/flutter#41573.

@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io labels Feb 23, 2022
@brianquinlan
Copy link
Contributor

It looks like "dictionary.cambridge.org" is doing some sort of user agent sniffing.

If I change the user agent with:

client.userAgent = 'curl/7.77.0';

Then the server produces a valid HTTP response.

@Rishyash
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io
Projects
None yet
Development

No branches or pull requests

4 participants