Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Make rawBody be the bytes #2215

Merged
merged 16 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
make isContentType textual private
  • Loading branch information
JeanJPNM committed Aug 16, 2021
commit 5c73398c12b7e1e1fe1b9d5da4a2107ca0dd3b02
3 changes: 0 additions & 3 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@
"./install-fetch": {
"import": "./dist/install-fetch.js"
},
"./adapter-utils": {
"import": "./dist/adapter-utils.js"
},
"./types": "./types/index.d.ts"
},
"types": "types/index.d.ts",
Expand Down
3 changes: 1 addition & 2 deletions packages/kit/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ export default [
cli: 'src/cli.js',
ssr: 'src/runtime/server/index.js',
node: 'src/core/node/index.js',
'install-fetch': 'src/install-fetch.js',
'adapter-utils': 'src/core/adapter-utils.js'
'install-fetch': 'src/install-fetch.js'
},
output: {
dir: 'dist',
Expand Down
18 changes: 0 additions & 18 deletions packages/kit/src/core/adapter-utils.js

This file was deleted.

20 changes: 18 additions & 2 deletions packages/kit/src/runtime/server/endpoint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isContentTypeTextual } from '../../core/adapter-utils.js';
import { lowercase_keys } from './utils.js';

/** @param {string} body */
Expand All @@ -15,6 +14,23 @@ function is_string(s) {
return typeof s === 'string' || s instanceof String;
}

/**
* Decides how the body should be parsed based on its mime type. Should match what's in parse_body
*
* @param {string | undefined | null} content_type The `content-type` header of a request/response.
* @returns {boolean}
*/
function is_content_type_textual(content_type) {
if (!content_type) return true; // defaults to json
const [type] = content_type.split(';'); // get the mime type
return (
type === 'text/plain' ||
type === 'application/json' ||
type === 'application/x-www-form-urlencoded' ||
type === 'multipart/form-data'
);
}

/**
* @param {import('types/hooks').ServerRequest} request
* @param {import('types/internal').SSREndpoint} route
Expand Down Expand Up @@ -48,7 +64,7 @@ export async function render_endpoint(request, route, match) {
headers = lowercase_keys(headers);
const type = headers['content-type'];

const is_type_textual = isContentTypeTextual(type);
const is_type_textual = is_content_type_textual(type);

if (!is_type_textual && !(body instanceof Uint8Array || is_string(body))) {
return error(
Expand Down