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

[Feature Request] Change auto generate header from http #505

Closed
MirzaHimamiHanif opened this issue Sep 28, 2023 · 4 comments · Fixed by #508
Closed

[Feature Request] Change auto generate header from http #505

MirzaHimamiHanif opened this issue Sep 28, 2023 · 4 comments · Fixed by #508
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@MirzaHimamiHanif
Copy link

Is your feature request related to a problem? Please describe.
http forced to add header with ; charset=utf-8 when doing request and I want my header without it.

Describe the solution you'd like
Need to change the order of http.Request(). First add the body then add the header.
image

Describe alternatives you've considered
No

Additional context

  1. This is chopper-7.0.6 that add header first then the body
    image
  2. New guide from http https://github.com/dart-lang/http/pull/1014/files

Before
image

After
image

@MirzaHimamiHanif MirzaHimamiHanif added the enhancement New feature or request label Sep 28, 2023
@MirzaHimamiHanif MirzaHimamiHanif changed the title Change auto generate header from http [Feature Request] Change auto generate header from http Sep 28, 2023
@techouse
Copy link
Collaborator

techouse commented Sep 29, 2023

Hey 👋

I see. You want to remove the charset when the body is in bytes (List<int>), but in cases where the payload is text, it should contain charset=utf-8, correct?

In that case, would this do

http.Request toHttpRequest() {
  final http.Request request = http.Request(method, url)
    ..followRedirects = followRedirects;

  if (body == null) {
    request.headers.addAll(headers);
  } else {
    if (body is String) {
      request
        ..headers.addAll(headers)
        ..body = body;
    } else if (body is List<int>) {
      request
        ..bodyBytes = body
        ..headers.addAll(headers);
    } else if (body is Map<String, String>) {
      request
        ..headers.addAll(headers)
        ..bodyFields = body;
    } else {
      throw ArgumentError.value('$body', 'body');
    }
  }

  return request;
}

@techouse
Copy link
Collaborator

techouse commented Oct 6, 2023

@MirzaHimamiHanif check if #508 fixes your problem

@techouse techouse added the bug Something isn't working label Oct 6, 2023
@mirzahimami
Copy link

Yes, thanks

@techouse
Copy link
Collaborator

techouse commented Oct 7, 2023

Cool, I'll add some unit tests to the PR and then merge it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants