github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/net/http/httptest/httptest.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // パッケージhttptestは、HTTPテストのためのユーティリティを提供します。 6 package httptest 7 8 import ( 9 "github.com/shogo82148/std/context" 10 "github.com/shogo82148/std/io" 11 "github.com/shogo82148/std/net/http" 12 ) 13 14 // NewRequestは、context.Backgroundを使用してNewRequestWithContextをラップします。 15 func NewRequest(method, target string, body io.Reader) *http.Request 16 17 // NewRequestWithContextは、新しい着信サーバーリクエストを返します。 18 // これはテストのために [http.Handler] に渡すのに適しています。 19 // 20 // targetはRFC 7230の「要求ターゲット」です。パスまたは絶対URLのいずれかを使用できます。targetが絶対URLの場合、URLからホスト名が使用されます。それ以外の場合は、"example.com"が使用されます。 21 // 22 // targetのスキームが「https」の場合、TLSフィールドは非nilのダミー値に設定されます。 23 // 24 // Request.Protoは常にHTTP/1.1です。 25 // 26 // 空のメソッドは「GET」を意味します。 27 // 28 // 指定されたbodyはnilである場合があります。bodyが*bytes.Reader、*strings.Reader、または*bytes.Bufferの型の場合、Request.ContentLengthが設定されます。 29 // 30 // NewRequestはエラー時にパニックを発生させます。テストではパニックが許容されるため、使用の便宜上です。 31 // 32 // サーバーリクエストの代わりにクライアントHTTPリクエストを生成するには、 33 // net/httpパッケージのNewRequest関数を参照してください。 34 func NewRequestWithContext(ctx context.Context, method, target string, body io.Reader) *http.Request