Node url.urlToHttpOptions function | API Reference | Bun
BuildDocsReferenceGuidesBlogDiscord/
node:url/
urlToHttpOptionsFurlToHttpOptions
Search the reference...
/
BuildDocsReferenceGuidesBlogDiscord/
node:url/
urlToHttpOptionsFurlToHttpOptions
function
url.urlToHttpOptionsfunction
urlToHttpOptions(url:
URL):
ClientRequestArgs;
This utility function converts a URL object into an ordinary options object as expected by the http.request() and https.request() APIs.
import { urlToHttpOptions } from 'node:url';
const myURL = new URL('https://a:b@測試?abc#foo');
console.log(urlToHttpOptions(myURL));
/*
{
protocol: 'https:',
hostname: 'xn--g6w251d',
hash: '#foo',
search: '?abc',
pathname: '/',
path: '/?abc',
href: 'https://a:b@xn--g6w251d/?abc#foo',
auth: 'a:b'
}
@param url
The WHATWG URL object to convert to an options object.
@returns
Options object
Referenced typesinterface
URLhash: string
host: string
hostname: string
href: stringreadonly
origin: string
password: string
pathname: string
port: string
protocol: string
search: stringreadonly
searchParams:
URLSearchParamsusername: string
toJSON(): string;interface
ClientRequestArgs_defaultAgent?:
Agentagent?: boolean |
Agentauth?: null | string
createConnection?: (options:
ClientRequestArgs, oncreate: (err: null |
Error, socket:
Duplex) => void) => undefined | null |
DuplexdefaultPort?: string | number
family?: number
headers?: readonly string[] |
OutgoingHttpHeadershints?: number
One or more supported getaddrinfo flags. Multiple flags may be passed by bitwise ORing their values.
host?: null | string
hostname?: null | string
insecureHTTPParser?: boolean
joinDuplicateHeaders?: boolean
localAddress?: string
localPort?: number
lookup?:
LookupFunctionmaxHeaderSize?: number
method?: string
path?: null | string
port?: null | string | number
protocol?: null | string
setDefaultHeaders?: boolean
setHost?: boolean
signal?:
AbortSignalsocketPath?: string
timeout?: number
uniqueHeaders?: string | string[][]
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlog Toolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →