sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
28 lines (22 loc) • 625 B
text/typescript
import {getIt} from 'get-it'
import {promise} from 'get-it/middleware'
const request = getIt([promise()])
export class HttpError extends Error {
statusCode?: number
}
export async function getUrlHeaders(url: string, headers = {}): Promise<Record<string, string>> {
const response = await request({
url,
stream: true,
maxRedirects: 0,
method: 'HEAD',
headers,
})
if (response.statusCode >= 400) {
const error = new HttpError(`Request returned HTTP ${response.statusCode}`)
error.statusCode = response.statusCode
throw error
}
response.body.resume()
return response.headers
}