CodeSampleX

샘플

http 1.6.0: Test code that calls an HTTP API with package:http using MockClient, with no network, and see what the client actually sends and decodes

검증된 샘플 — pub http 1.6.0: Test code that calls an HTTP API with package:http using MockClient, with no network, and see what the client actually sends and…

sha256:ed3c594714b9ed323ec4da016bdf6f9e47b615cc78872cab62588dd0532e98b7

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 dart 3 linux x64 dart 3 dart pub

검증 실행 환경

환경 컨트랙트 단계 실행일
dart 3 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · pub@1
2026-08-14
dart 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · pub@1
2026-08-18

케이스

HOW
목표
Test code that calls an HTTP API with package:http using MockClient, with no network, and see what the client actually sends and decodes
패키지
심벌
  • MockClient
  • Client.get
  • Client.post
  • Client.read
  • Response.body
  • Response.bodyBytes
  • Request.bodyFields
  • MultipartRequest
  • ClientException
환경
dart 3
생성일
2026-08-14T09:40:43Z

컨트랙트

  1. assert the MockClient handler receives the finalized request the client built, with its url and query, headers that look up case-insensitively but keep the case you wrote, and an empty GET body
  2. assert the handler argument is a rebuilt plain Request rather than your object, so a MultipartRequest arrives flattened to its encoded body and boundary header, and the request you sent comes back finalized
  3. assert a 404 does not throw from get: the Future completes, the error body decodes like any payload, and only statusCode and reasonPhrase report it
  4. assert read and readBytes are the exception and throw a ClientException at status 400 and above, with the server's error body no longer reachable, while 399 is read back as a body
  5. assert response.body decodes application/json without a charset as utf8 but falls back to latin1 for text/plain, text/html, application/xml, a vendor +json subtype and a missing content-type, while bodyBytes stays raw
  6. assert a Map body is form-encoded as application/x-www-form-urlencoded with percent-encoded utf8 and no charset parameter appended
  7. assert a declared JSON content-type stays exactly application/json with utf8 bytes on the wire, while an undeclared String body is announced as text/plain; charset=utf-8 and a declared application/xml gains charset=utf-8
  8. assert passing a Map under a JSON content-type throws StateError from Request.bodyFields instead of silently mis-encoding
  9. assert a ClientException thrown by the handler propagates unwrapped with its message and uri, and any other exception type propagates with its own type

파일

  • csx.json
  • lib/users.dart
  • pubspec.lock
  • pubspec.yaml
  • test/contract_test.dart

소스 아티팩트 내려받기 (tar.gz)

오리진 시더

anonymous