http icon indicating copy to clipboard operation
http copied to clipboard

Client sends headers out of order.

Open owenkealey opened this issue 3 years ago • 1 comments

Hi,

I am working against a site that requires the headers of a particular request ot be sent in a particular order.

However, the http client seems to send the headers out of order every time.

For example, consider this simple test to run against the library

@TestOn('vm')

import 'package:http/http.dart' as http;
import 'package:test/test.dart';

import 'utils.dart';

void main() {
  setUp(startServer);

  tearDown(stopServer);

  test('send happy case', () async {
    Map<String, String> headers = {
      "a": "test",
      "b": "test",
      "c": "test",
      "d": "test"
    };
    final request =
        http.get(Uri.parse("http://127.0.0.1:5000"), headers: headers);

    final response = await request;

    expect(response.statusCode, equals(200));
  });
}

You can see that I set the headers in alphabetical order.

The test hits a simple Python flask server:

from flask import Flask, request

app = Flask(__name__)

@app.route("/")
def hello_world():
    print(request.headers)
    return "<p>Hello, World!</p>"

The expected result is that the headers are sent in order(in this case the order happens to be alphabetical). Instead, the orders are received like so on the server side:

User-Agent: Dart/2.16 (dart:io)
A: test
Accept-Encoding: gzip
D: test
Host: 127.0.0.1:5000
C: test
B: test

Completely out of order.

owenkealey avatar Feb 11 '22 20:02 owenkealey

Header ordering does not carry significance in the HTTP spec. I don't think we'd want to have special code in package:http to handle a concern which doesn't impact behavior for spec-compliant servers.

It's a little bit more serious if this doesn't work with the Http client from dart:io since there might not be a workaround from there. Does this work if you use HttpClient from dart:io instead of package:http?

natebosch avatar Feb 16 '22 00:02 natebosch