better-call 1.0.28 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -133,10 +133,16 @@ async function getBody(request, allowedMediaTypes) {
133
133
  const normalizedContentTypeBase = normalizedContentType.split(";")[0].trim();
134
134
  const normalizedAllowed = allowed.toLowerCase().trim();
135
135
  return normalizedContentTypeBase === normalizedAllowed || normalizedContentTypeBase.includes(normalizedAllowed);
136
- })) throw new APIError(415, {
137
- message: `Content-Type "${contentType}" is not allowed. Allowed types: ${allowedMediaTypes.join(", ")}`,
138
- code: "UNSUPPORTED_MEDIA_TYPE"
139
- });
136
+ })) {
137
+ if (!normalizedContentType) throw new APIError(415, {
138
+ message: `Content-Type is required. Allowed types: ${allowedMediaTypes.join(", ")}`,
139
+ code: "UNSUPPORTED_MEDIA_TYPE"
140
+ });
141
+ throw new APIError(415, {
142
+ message: `Content-Type "${contentType}" is not allowed. Allowed types: ${allowedMediaTypes.join(", ")}`,
143
+ code: "UNSUPPORTED_MEDIA_TYPE"
144
+ });
145
+ }
140
146
  }
141
147
  if (normalizedContentType.includes("application/json")) return await request.json();
142
148
  if (normalizedContentType.includes("application/x-www-form-urlencoded")) {
@@ -212,12 +218,14 @@ function toResponse(data, init) {
212
218
  const body$1 = data.body;
213
219
  const routerResponse = data.routerResponse;
214
220
  if (routerResponse instanceof Response) return routerResponse;
215
- const headers$1 = new Headers({
216
- ...routerResponse?.headers,
217
- ...data.headers,
218
- ...init?.headers,
219
- "Content-Type": "application/json"
220
- });
221
+ const headers$1 = new Headers();
222
+ if (routerResponse?.headers) {
223
+ const headers$2 = new Headers(routerResponse.headers);
224
+ for (const [key, value] of headers$2.entries()) headers$2.set(key, value);
225
+ }
226
+ if (data.headers) for (const [key, value] of new Headers(data.headers).entries()) headers$1.set(key, value);
227
+ if (init?.headers) for (const [key, value] of new Headers(init.headers).entries()) headers$1.set(key, value);
228
+ headers$1.set("Content-Type", "application/json");
221
229
  return new Response(JSON.stringify(body$1), {
222
230
  ...routerResponse,
223
231
  headers: headers$1,