github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/net/http/filetransport.go (about)

     1  // Copyright 2011 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  package http
     6  
     7  import (
     8  	"github.com/shogo82148/std/io/fs"
     9  )
    10  
    11  // NewFileTransportは、提供された [FileSystem] を提供する新しい [RoundTripper] を返します。
    12  // 返されたRoundTripperは、その入力リクエストのURLホストを無視します。また、リクエストの
    13  // 他のほとんどのプロパティも無視します。
    14  //
    15  // NewFileTransport の典型的な使用例は、[Transport] に "file" プロトコルを登録することです。
    16  // 例:
    17  //
    18  //	t := &http.Transport{}
    19  //	t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))
    20  //	c := &http.Client{Transport: t}
    21  //	res, err := c.Get("file:///etc/passwd")
    22  //	...
    23  func NewFileTransport(fs FileSystem) RoundTripper
    24  
    25  // NewFileTransportFS returns a new [RoundTripper], serving the provided
    26  // file system fsys. The returned RoundTripper ignores the URL host in its
    27  // incoming requests, as well as most other properties of the
    28  // request.
    29  //
    30  // The typical use case for NewFileTransportFS is to register the "file"
    31  // protocol with a [Transport], as in:
    32  //
    33  //	fsys := os.DirFS("/")
    34  //	t := &http.Transport{}
    35  //	t.RegisterProtocol("file", http.NewFileTransportFS(fsys))
    36  //	c := &http.Client{Transport: t}
    37  //	res, err := c.Get("file:///etc/passwd")
    38  //	...
    39  func NewFileTransportFS(fsys fs.FS) RoundTripper