Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
¿Qué tipos de Mime contienen la directiva charset=utf-8?

Para facilitar la visualización, a continuación se muestra la siguiente tabla de búsqueda de registros.

Parece que no puedo encontrar ningún lugar en línea donde te diga cuáles de estos se supone que también contienen charset=utf-8 .

¿Debo asumir que es algo similar al texto?

Echar un vistazo:

 const MEDIA_TYPES: Record<string, string> = { ".md": "text/markdown", ".html": "text/html", ".htm": "text/html", ".json": "application/json", ".map": "application/json", ".txt": "text/plain", ".ts": "text/typescript", ".tsx": "text/tsx", ".js": "application/javascript", ".jsx": "text/jsx", ".gz": "application/gzip", ".css": "text/css", ".wasm": "application/wasm", ".mjs": "application/javascript", ".otf": "font/otf", ".ttf": "font/ttf", ".woff": "font/woff", ".woff2": "font/woff2", ".conf": "text/plain", ".list": "text/plain", ".log": "text/plain", ".ini": "text/plain", ".vtt": "text/vtt", ".yaml": "text/yaml", ".yml": "text/yaml", ".mid": "audio/midi", ".midi": "audio/midi", ".mp3": "audio/mp3", ".mp4a": "audio/mp4", ".m4a": "audio/mp4", ".ogg": "audio/ogg", ".spx": "audio/ogg", ".opus": "audio/ogg", ".wav": "audio/wav", ".webm": "audio/webm", ".aac": "audio/x-aac", ".flac": "audio/x-flac", ".mp4": "video/mp4", ".mp4v": "video/mp4", ".mkv": "video/x-matroska", ".mov": "video/quicktime", ".svg": "image/svg+xml", ".avif": "image/avif", ".bmp": "image/bmp", ".gif": "image/gif", ".heic": "image/heic", ".heif": "image/heif", ".jpeg": "image/jpeg", ".jpg": "image/jpeg", ".png": "image/png", ".tiff": "image/tiff", ".psd": "image/vnd.adobe.photoshop", ".ico": "image/vnd.microsoft.icon", ".webp": "image/webp", ".es": "application/ecmascript", ".epub": "application/epub+zip", ".jar": "application/java-archive", ".war": "application/java-archive", ".webmanifest": "application/manifest+json", ".doc": "application/msword", ".dot": "application/msword", ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ".dotx": "application/vnd.openxmlformats-officedocument.wordprocessingml.template", ".cjs": "application/node", ".bin": "application/octet-stream", ".pkg": "application/octet-stream", ".dump": "application/octet-stream", ".exe": "application/octet-stream", ".deploy": "application/octet-stream", ".img": "application/octet-stream", ".msi": "application/octet-stream", ".pdf": "application/pdf", ".pgp": "application/pgp-encrypted", ".asc": "application/pgp-signature", ".sig": "application/pgp-signature", ".ai": "application/postscript", ".eps": "application/postscript", ".ps": "application/postscript", ".rdf": "application/rdf+xml", ".rss": "application/rss+xml", ".rtf": "application/rtf", ".apk": "application/vnd.android.package-archive", ".key": "application/vnd.apple.keynote", ".numbers": "application/vnd.apple.keynote", ".pages": "application/vnd.apple.pages", ".geo": "application/vnd.dynageo", ".gdoc": "application/vnd.google-apps.document", ".gslides": "application/vnd.google-apps.presentation", ".gsheet": "application/vnd.google-apps.spreadsheet", ".kml": "application/vnd.google-earth.kml+xml", ".mkz": "application/vnd.google-earth.kmz", ".icc": "application/vnd.iccprofile", ".icm": "application/vnd.iccprofile", ".xls": "application/vnd.ms-excel", ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ".xlm": "application/vnd.ms-excel", ".ppt": "application/vnd.ms-powerpoint", ".pot": "application/vnd.ms-powerpoint", ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation", ".potx": "application/vnd.openxmlformats-officedocument.presentationml.template", ".xps": "application/vnd.ms-xpsdocument", ".odc": "application/vnd.oasis.opendocument.chart", ".odb": "application/vnd.oasis.opendocument.database", ".odf": "application/vnd.oasis.opendocument.formula", ".odg": "application/vnd.oasis.opendocument.graphics", ".odp": "application/vnd.oasis.opendocument.presentation", ".ods": "application/vnd.oasis.opendocument.spreadsheet", ".odt": "application/vnd.oasis.opendocument.text", ".rar": "application/vnd.rar", ".unityweb": "application/vnd.unity", ".dmg": "application/x-apple-diskimage", ".bz": "application/x-bzip", ".crx": "application/x-chrome-extension", ".deb": "application/x-debian-package", ".php": "application/x-httpd-php", ".iso": "application/x-iso9660-image", ".sh": "application/x-sh", ".sql": "application/x-sql", ".srt": "application/x-subrip", ".xml": "application/xml", ".zip": "application/zip", }; /** Returns the content-type based on the extension of a path. */ function contentType(pathname: string): string | undefined { return MEDIA_TYPES[pathname]; } console.log(contentType("/dashboard/v1/index.html")); console.log(contentType("/dashboard/v1/logo.svg"));
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

MDN dice:

Por ejemplo, para cualquier tipo MIME cuyo tipo principal sea texto, puede agregar el parámetro charset opcional para especificar el juego de caracteres utilizado para los caracteres de los datos. Si no se especifica ningún conjunto de caracteres, el valor predeterminado es ASCII (US-ASCII), a menos que la configuración del agente de usuario lo anule. Para especificar un archivo de texto UTF-8, se utiliza el tipo MIME text/plain;charset=UTF-8.

Entonces, para cualquier cosa basada en text/... Opcionalmente, puede agregar el juego de caracteres.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#structure_of_a_mime_type

La siguiente actualización de la función contentType() demuestra una solución.

 /** Returns the content-type based on the extension of a path. */ function contentType(ext: string): string | undefined { const charsetUtf8 = "; charset=UTF-8"; // Content types that do not start with text/.. but usually contain charset=utf-8 const specialCase = [ "application/json", "application/xml", "application/rss+xml", ]; let outputContentType = MEDIA_TYPES[ext]; // Return undefined. if(!outputContentType) return; if(outputContentType.startsWith("text/") || specialCase.includes(outputContentType)) { // Combine Content-Type with charset=utf-8 outputContentType = outputContentType + charsetUtf8; // Return combined. return outputContentType; } else { // Return for any other types or undefined. return outputContentType; } }

Entonces, en teoría, podría devolver un 422: Unprocessable Entity no procesable en cualquier tipo de contenido que NO esté presente en la lista de tipos MIME.

 let requestedFilePath = path.join("./", context.main.http.server.root, urlPathNameParsed.dir, urlPathNameParsed.base); try { // try as file... const file = await Deno.readFile(requestedFilePath); // If file extension is not on media list... if(typeof(contentType(urlPathNameParsed.ext)) === 'undefined') { // Set Content-Type header for this response responseHeaders.set('Content-Type', 'text/plain; charset=UTF-8'); await e.respondWith( new Response("HTTP 422: Unprocessable Entity", { headers: responseHeaders, status: 422, statusText: 'Unprocessable Entity', }) ); } else { // Set Content-Type header for this response responseHeaders.set('Content-Type', `${contentType(urlPathNameParsed.ext)}`); // Build and send the response await e.respondWith( new Response(file, { headers: responseHeaders, status: 200, statusText: 'OK' }) ); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!