Skip to content

Commit

Permalink
fix: duplex half once
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jun 15, 2023
1 parent 19f0acb commit fb64bd3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions packages/primitives/src/primitives/fetch.js
Expand Up @@ -20,7 +20,7 @@ process.nextTick = setImmediate
process.emitWarning = () => {}

class Request extends BaseRequest {
constructor(input, init) {
constructor (input, init) {
super(input, addDuplexToInit(init))
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ ResponseModule.Response.error = function (...args) {
* @param {string} potentialName
* @param {'Header.append' | 'Headers.delete' | 'Headers.get' | 'Headers.has' | 'Header.set'} errorPrefix
*/
function normalizeAndValidateHeaderName(potentialName, errorPrefix) {
function normalizeAndValidateHeaderName (potentialName, errorPrefix) {
const normalizedName = potentialName.toLowerCase()

if (UtilModule.isValidHeaderName(normalizedName)) {
Expand All @@ -93,7 +93,7 @@ function normalizeAndValidateHeaderName(potentialName, errorPrefix) {
WebIDLModule.errors.invalidArgument({
prefix: errorPrefix,
value: normalizedName,
type: 'header name',
type: 'header name'
})
}

Expand All @@ -103,7 +103,7 @@ function normalizeAndValidateHeaderName(potentialName, errorPrefix) {
* @param {string} potentialValue
* @param {'Header.append' | 'Header.set'} errorPrefix
*/
function normalizeAndValidateHeaderValue(potentialValue, errorPrefix) {
function normalizeAndValidateHeaderValue (potentialValue, errorPrefix) {
/**
* To normalize a byte sequence potentialValue, remove
* any leading and trailing HTTP whitespace bytes from
Expand All @@ -121,7 +121,7 @@ function normalizeAndValidateHeaderValue(potentialValue, errorPrefix) {
WebIDLModule.errors.invalidArgument({
prefix: errorPrefix,
value: normalizedValue,
type: 'header value',
type: 'header value'
})
}

Expand All @@ -131,11 +131,11 @@ function normalizeAndValidateHeaderValue(potentialValue, errorPrefix) {
*/
let globalDispatcher = new Agent()

export function getGlobalDispatcher() {
export function getGlobalDispatcher () {
return globalDispatcher
}

export function setGlobalDispatcher(agent) {
export function setGlobalDispatcher (agent) {
if (!agent || typeof agent.dispatch !== 'function') {
throw new InvalidArgumentError('Argument agent must implement Agent')
}
Expand All @@ -145,19 +145,19 @@ export function setGlobalDispatcher(agent) {
/**
* Add `duplex: 'half'` by default to all requests
*/
function addDuplexToInit(init) {
if (typeof init === 'undefined' || typeof init === 'object') {
return { duplex: 'half', ...init }
}
return init
function addDuplexToInit (init) {
return typeof init === 'undefined' ||
(typeof init === 'object' && init.duplex !== 'half')
? { duplex: 'half', ...init }
: init
}

/**
* Export fetch with an implementation that uses a default global dispatcher.
* It also re-cretates a new Response object in order to allow mutations on
* the Response headers.
*/
export async function fetch(info, init) {
export async function fetch (info, init) {
init = addDuplexToInit(init)
const res = await fetchImpl.call(getGlobalDispatcher(), info, init)
const response = new Response(res.body, res)
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/cli/repl.ts
Expand Up @@ -14,7 +14,7 @@ const writer: createRepl.REPLWriter = (output) => {
}

const repl = createRepl.start({ prompt: 'ƒ => ', writer })
repl.setupHistory(join(homedir(), '.edge_runtime_repl_history'), () => { })
repl.setupHistory(join(homedir(), '.edge_runtime_repl_history'), () => {})

Object.getOwnPropertyNames(repl.context).forEach(
(mod) => delete repl.context[mod]
Expand Down

0 comments on commit fb64bd3

Please sign in to comment.