<commit_before>// Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library http_test;

import 'dart:io';

import '../../unittest/lib/unittest.dart';
import '../lib/http.dart' as http;
import 'utils.dart';

main() {
  group('http.', () {
    setUp(startServer);
    tearDown(stopServer);

    test('head', () {
      expect(http.head(serverUrl).transform((response) {
        expect(response.statusCode, equals(200));
        expect(response.body, equals(''));
      }), completes);
    });

    test('get', () {
      expect(http.get(serverUrl, headers: {
        'X-Random-Header': 'Value',
        'X-Other-Header': 'Other Value'
      }).transform((response) {
        expect(response.statusCode, equals(200));
        expect(response.body, parse(equals({
          'method': 'GET',
          'path': '/',
          'headers': {
            'content-length': ['0'],
            'x-random-header': ['Value'],
            'x-other-header': ['Other Value']
          },
        })));
      }), completes);
    });

    test('post', () {
      expect(http.post(serverUrl, headers: {
        'X-Random-Header': 'Value',
        'X-Other-Header': 'Other Value'
      }, fields: {
        'some-field': 'value',
        'other-field': 'other value'
      }).transform((response) {
        expect(response.statusCode, equals(200));
        expect(response.body, parse(equals({
          'method': 'POST',
          'path': '/',
          'headers': {
            'content-type': [
              'application/x-www-form-urlencoded; charset=UTF-8'
            ],
            'content-length': ['42'],
            'x-random-header': ['Value'],
            'x-other-header': ['Other Value']
          },
          'body': 'some-field=value&other-field=other%20value'
        })));
      }), completes);
    });

    test('post without fields', () {
      expect(http.post(serverUrl, headers: {
        'X-Random-Header': 'Value',
        'X-Other-Header': 'Other Value',
        'Content-Type': 'text/plain'
      }).transform((response) {
        expect(response.statusCode, equals(200));
        expect(response.body, parse(equals({
          'method': 'POST',
          'path': '/',
          'headers': {
            'content-length': ['0'],
            'content-type': ['text/plain'],
            'x-random-header': ['Value'],
            'x-other-header': ['Other Value']
          }
        })));
      }), completes);
    });

    test('put', () {
      expect(http.put(serverUrl, headers: {
        'X-Random-Header': 'Value',
        'X-Other-Header': 'Other Value'
      }, fields: {
        'some-field': 'value',
        'other-field': 'other value'
      }).transform((response) {
        expect(response.statusCode, equals(200));
        expect(response.body, parse(equals({
          'method': 'PUT',
          'path': '/',
          'headers': {
            'content-type': [
              'application/x-www-form-urlencoded; charset=UTF-8'
            ],
            'content-length': ['42'],
            'x-random-header': ['Value'],
            'x-other-header': ['Other Value']
          },
          'body': 'some-field=value&other-field=other%20value'
        })));
      }), completes);
    });

    test('put without fields', () {<commit_msg>Reapply "Fix URI encoding/decoding of + and space""<commit_after>// Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library http_test;

import 'dart:io';

import '../../unittest/lib/unittest.dart';
import '../lib/http.dart' as http;
import 'utils.dart';

main() {
  group('http.', () {
    setUp(startServer);
    tearDown(stopServer);

    test('head', () {
      expect(http.head(serverUrl).transform((response) {
        expect(response.statusCode, equals(200));
        expect(response.body, equals(''));
      }), completes);
    });

    test('get', () {
      expect(http.get(serverUrl, headers: {
        'X-Random-Header': 'Value',
        'X-Other-Header': 'Other Value'
      }).transform((response) {
        expect(response.statusCode, equals(200));
        expect(response.body, parse(equals({
          'method': 'GET',
          'path': '/',
          'headers': {
            'content-length': ['0'],
            'x-random-header': ['Value'],
            'x-other-header': ['Other Value']
          },
        })));
      }), completes);
    });

    test('post', () {
      expect(http.post(serverUrl, headers: {
        'X-Random-Header': 'Value',
        'X-Other-Header': 'Other Value'
      }, fields: {
        'some-field': 'value',
        'other-field': 'other value'
      }).transform((response) {
        expect(response.statusCode, equals(200));
        expect(response.body, parse(equals({
          'method': 'POST',
          'path': '/',
          'headers': {
            'content-type': [
              'application/x-www-form-urlencoded; charset=UTF-8'
            ],
            'content-length': ['40'],
            'x-random-header': ['Value'],
            'x-other-header': ['Other Value']
          },
          'body': 'some-field=value&other-field=other+value'
        })));
      }), completes);
    });

    test('post without fields', () {
      expect(http.post(serverUrl, headers: {
        'X-Random-Header': 'Value',
        'X-Other-Header': 'Other Value',
        'Content-Type': 'text/plain'
      }).transform((response) {
        expect(response.statusCode, equals(200));
        expect(response.body, parse(equals({
          'method': 'POST',
          'path': '/',
          'headers': {
            'content-length': ['0'],
            'content-type': ['text/plain'],
            'x-random-header': ['Value'],
            'x-other-header': ['Other Value']
          }
        })));
      }), completes);
    });

    test('put', () {
      expect(http.put(serverUrl, headers: {
        'X-Random-Header': 'Value',
        'X-Other-Header': 'Other Value'
      }, fields: {
        'some-field': 'value',
        'other-field': 'other value'
      }).transform((response) {
        expect(response.statusCode, equals(200));
        expect(response.body, parse(equals({
          'method': 'PUT',
          'path': '/',
          'headers': {
            'content-type': [
              'application/x-www-form-urlencoded; charset=UTF-8'
            ],
            'content-length': ['40'],
            'x-random-header': ['Value'],
            'x-other-header': ['Other Value']
          },
          'body': 'some-field=value&other-field=other+value'
        })));
      }), completes);
    });

    test('put without fields', () {
{'fraction_non_alphanumeric': 0.18880813953488373, 'fraction_numerical': 0.008430232558139536, 'mean_word_length': 1.9800779558250325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4398205', 'n_tokens_mistral': 2064, 'n_tokens_neox': 2005, 'n_words': 388}