diff --git a/src/Puppeteer.Page.HTTP.Request.js b/src/Puppeteer.Page.HTTP.Request.js index 0b0d8e2..b9776ce 100644 --- a/src/Puppeteer.Page.HTTP.Request.js +++ b/src/Puppeteer.Page.HTTP.Request.js @@ -2,71 +2,63 @@ import { HTTPResponse } from 'puppeteer' import { HTTPRequest } from 'puppeteer' /** - * `foreign import _abort :: String -> Request -> Promise Unit` * @type {(_0: import("puppeteer").ErrorCode) => (_1: HTTPRequest) => () => Promise} */ export const _abort = e => r => () => r.abort(e) /** - * `foreign import _continue :: Foreign -> Request -> Promise Unit` * @type {(_0: import("puppeteer").ContinueRequestOverrides) => (_1: HTTPRequest) => () => Promise} */ export const _continue = o => r => () => r.continue(o) /** - * `foreign import _respond :: RespondToRequest -> Request -> Promise Unit` * @type {(_0: import("puppeteer").ResponseForRequest) => (_1: HTTPRequest) => () => Promise} */ export const _respond = rep => req => () => req.respond(rep) /** - * `foreign import _failure :: Request -> Effect (Nullable {errorText :: String})` * @type {(_1: HTTPRequest) => () => {errorText: string} | null} */ export const _failure = r => () => r.failure() /** - * `foreign import headers :: Request -> Effect (Map String String)` - * @type {(_1: HTTPRequest) => () => Map} + * @type {(_1: HTTPRequest) => () => Array<{k: string, v: string}>} */ -export const headers = r => () => - Object.entries(r.headers()).reduce((map, [k, v]) => { - map.set(k, v) - return map - }, new Map()) +export const headers = r => () => { + /** @type {Array<{k: string, v: string}>} */ + const init = [] + return Object.entries(r.headers()).reduce( + (map, [k, v]) => [...map, { k, v }], + init, + ) +} /** - * `foreign import _isNavigation :: Request -> Effect Boolean` * @type {(_1: HTTPRequest) => () => boolean} */ export const isNavigation = r => () => r.isNavigationRequest() /** - * `foreign import _method :: Request -> Effect String` * @type {(_1: HTTPRequest) => () => string} */ export const method = r => () => r.method() /** - * `foreign import _postData :: Request -> Effect Foreign` * @type {(_1: HTTPRequest) => () => string | undefined} */ export const _postData = r => () => r.postData() /** - * `foreign import _resourceType :: Request -> Effect String` * @type {(_1: HTTPRequest) => () => string} */ export const resourceType = r => () => r.resourceType() /** - * `foreign import _url :: Request -> Effect String` * @type {(_1: HTTPRequest) => () => string} */ export const url = r => () => r.url() /** - * `foreign import _response :: Request -> Effect (Nullable Response)` * @type {(_1: HTTPRequest) => () => HTTPResponse | null} */ export const _response = r => () => r.response() diff --git a/src/Puppeteer.Page.HTTP.Request.purs b/src/Puppeteer.Page.HTTP.Request.purs index 6a89bf6..d213de4 100644 --- a/src/Puppeteer.Page.HTTP.Request.purs +++ b/src/Puppeteer.Page.HTTP.Request.purs @@ -9,6 +9,11 @@ module Puppeteer.HTTP.Request , failure , postData , response + , headers + , isNavigation + , method + , resourceType + , url ) where import Prelude @@ -67,7 +72,6 @@ prepareContinueRequestOverrides { headers: headers', method: method', postData: , url: FFI.maybeToUndefined url' } -foreign import headers :: Request -> Effect (Map String String) foreign import isNavigation :: Request -> Effect Boolean foreign import method :: Request -> Effect String foreign import resourceType :: Request -> Effect String @@ -77,10 +81,14 @@ foreign import _abort :: String -> Request -> Promise Unit foreign import _continue :: Foreign -> Request -> Promise Unit foreign import _respond :: Foreign -> Request -> Promise Unit +foreign import _headers :: Request -> Effect (Array {k :: String, v :: String}) foreign import _failure :: Request -> Effect (Nullable { errorText :: String }) foreign import _postData :: Request -> Effect Foreign foreign import _response :: Request -> Effect (Nullable Response) +headers :: Request -> Effect (Map String String) +headers = map FFI.makeMap <<< _headers + abort :: Context InterceptRequestsHint -> ErrorCode -> Request -> Aff Unit abort _ e = Promise.toAff <<< _abort (errorCodeString e)