Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/functions/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { promises as fs } from 'fs'
import type { IncomingHttpHeaders } from 'http'
import path from 'path'

import { shouldBase64Encode } from '@netlify/dev-utils'
import express, { type Request, type RequestHandler } from 'express'
import expressLogging from 'express-logging'
import { jwtDecode } from 'jwt-decode'
Expand All @@ -29,7 +30,6 @@ import { createFormSubmissionHandler } from './form-submissions-handler.js'
import { FunctionsRegistry } from './registry.js'
import { handleScheduledFunction } from './scheduled.js'
import { handleSynchronousFunction } from './synchronous.js'
import { shouldBase64Encode } from './utils.js'

type FunctionsSettings = Pick<ServerSettings, 'functions' | 'functionsPort'>

Expand Down Expand Up @@ -122,7 +122,7 @@ export const createHandler = function (options: GetFunctionsServerOptions): Requ
return
}

const isBase64Encoded = shouldBase64Encode(request.header('content-type'))
const isBase64Encoded = shouldBase64Encode(request.header('content-type') ?? '')
let body
if (hasBody(request)) {
body = request.body.toString(isBase64Encoded ? 'base64' : 'utf8')
Expand Down
35 changes: 0 additions & 35 deletions src/lib/functions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,4 @@ export const formatLambdaError = (err: Error | InvocationError): string =>
`${'errorType' in err ? err.errorType : 'Error'}: ${'errorMessage' in err ? err.errorMessage : err.message}`,
)

// should be equivalent to https://github.com/netlify/proxy/blob/main/pkg/functions/request.go#L105
const exceptionsList = new Set([
'application/csp-report',
'application/graphql',
'application/json',
'application/javascript',
'application/x-www-form-urlencoded',
'application/x-ndjson',
'application/xml',
])

export const shouldBase64Encode = function (contentType?: string): boolean {
if (!contentType) {
return true
}

const [contentTypeSegment] = contentType.split(';')
contentType = contentTypeSegment
contentType = contentType.toLowerCase()

if (contentType.startsWith('text/')) {
return false
}

if (contentType.endsWith('+json') || contentType.endsWith('+xml')) {
return false
}

if (exceptionsList.has(contentType)) {
return false
}

return true
}

export const styleFunctionName = (name: string): string => chalk.magenta(name)
Loading