| 48 | } |
| 49 | |
| 50 | func newFastHTTPClient(opts *clientOpts) client { |
| 51 | c := new(fasthttpClient) |
| 52 | uri := fasthttp.AcquireURI() |
| 53 | if err := uri.Parse( |
| 54 | []byte(opts.requestURL.Host), |
| 55 | []byte(opts.requestURL.String()), |
| 56 | ); err != nil { |
| 57 | // opts.requestURL must always be valid |
| 58 | panic(err) |
| 59 | } |
| 60 | c.uri = uri |
| 61 | c.client = &fasthttp.Client{ |
| 62 | MaxConnsPerHost: int(opts.maxConns), |
| 63 | ReadTimeout: opts.timeout, |
| 64 | WriteTimeout: opts.timeout, |
| 65 | DisableHeaderNamesNormalizing: true, |
| 66 | TLSConfig: opts.tlsConfig, |
| 67 | Dial: fasthttpDialFunc( |
| 68 | opts.bytesRead, opts.bytesWritten, |
| 69 | opts.timeout, |
| 70 | ), |
| 71 | } |
| 72 | c.headers = headersToFastHTTPHeaders(opts.headers) |
| 73 | c.method, c.body = opts.method, opts.body |
| 74 | c.bodProd = opts.bodProd |
| 75 | return client(c) |
| 76 | } |
| 77 | |
| 78 | func (c *fasthttpClient) do() ( |
| 79 | code int, usTaken uint64, err error, |