diff --git a/Cargo.lock b/Cargo.lock index 5ae7b509cb..8f76d85db0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -966,6 +966,7 @@ version = "0.43.0" dependencies = [ "async-compression", "base64 0.13.0", + "bencher", "brotli", "bytes", "cache_control", @@ -976,6 +977,7 @@ dependencies = [ "hyper", "mime", "percent-encoding", + "phf", "ring", "serde", "tokio", diff --git a/ext/http/Cargo.toml b/ext/http/Cargo.toml index f0789e37b9..feb27ae420 100644 --- a/ext/http/Cargo.toml +++ b/ext/http/Cargo.toml @@ -13,6 +13,10 @@ description = "HTTP server implementation for Deno" [lib] path = "lib.rs" +[[bench]] +name = "compressible" +harness = false + [dependencies] async-compression = { version = "0.3.1", features = ["tokio", "brotli", "gzip"] } base64 = "0.13.0" @@ -26,7 +30,11 @@ fly-accept-encoding = "0.2.0-alpha.5" hyper = { version = "0.14.9", features = ["server", "stream", "http1", "http2", "runtime"] } mime = "0.3.16" percent-encoding = "2.1.0" +phf = { version = "0.10", features = ["macros"] } ring = "0.16.20" serde = { version = "1.0.129", features = ["derive"] } tokio = { version = "1.17", features = ["full"] } tokio-util = { version = "0.7.0", features = ["io"] } + +[dev-dependencies] +bencher = "0.1" diff --git a/ext/http/benches/compressible.rs b/ext/http/benches/compressible.rs new file mode 100644 index 0000000000..bdd3bcad8f --- /dev/null +++ b/ext/http/benches/compressible.rs @@ -0,0 +1,37 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use bencher::{benchmark_group, benchmark_main, Bencher}; +use deno_http::compressible::is_content_compressible; + +fn compressible_simple_hit(b: &mut Bencher) { + b.iter(|| { + is_content_compressible("text/plain"); + }) +} + +fn compressible_complex_hit(b: &mut Bencher) { + b.iter(|| { + is_content_compressible("text/PlAIn; charset=utf-8"); + }) +} + +fn compressible_simple_miss(b: &mut Bencher) { + b.iter(|| { + is_content_compressible("text/fake"); + }) +} + +fn compressible_complex_miss(b: &mut Bencher) { + b.iter(|| { + is_content_compressible("text/fake;charset=utf-8"); + }) +} + +benchmark_group!( + benches, + compressible_simple_hit, + compressible_complex_hit, + compressible_simple_miss, + compressible_complex_miss, +); + +benchmark_main!(benches); diff --git a/ext/http/compressible.rs b/ext/http/compressible.rs index b85f4a325e..d3c1fc7a8d 100644 --- a/ext/http/compressible.rs +++ b/ext/http/compressible.rs @@ -1,658 +1,656 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -use deno_core::ByteString; +use phf::phf_set; +use std::str::FromStr; // Data obtained from https://github.com/jshttp/mime-db/blob/fa5e4ef3cc8907ec3c5ec5b85af0c63d7059a5cd/db.json // Important! Keep this list sorted alphabetically. -const CONTENT_TYPES: &[&str] = &[ - "application/3gpdash-qoe-report+xml", - "application/3gpp-ims+xml", - "application/3gpphal+json", - "application/3gpphalforms+json", - "application/activity+json", - "application/alto-costmap+json", - "application/alto-costmapfilter+json", - "application/alto-directory+json", - "application/alto-endpointcost+json", - "application/alto-endpointcostparams+json", - "application/alto-endpointprop+json", - "application/alto-endpointpropparams+json", - "application/alto-error+json", - "application/alto-networkmap+json", - "application/alto-networkmapfilter+json", - "application/alto-updatestreamcontrol+json", - "application/alto-updatestreamparams+json", - "application/atom+xml", - "application/atomcat+xml", - "application/atomdeleted+xml", - "application/atomsvc+xml", - "application/atsc-dwd+xml", - "application/atsc-held+xml", - "application/atsc-rdt+json", - "application/atsc-rsat+xml", - "application/auth-policy+xml", - "application/beep+xml", - "application/calendar+json", - "application/calendar+xml", - "application/captive+json", - "application/ccmp+xml", - "application/ccxml+xml", - "application/cdfx+xml", - "application/cea-2018+xml", - "application/cellml+xml", - "application/clue+xml", - "application/clue_info+xml", - "application/cnrp+xml", - "application/coap-group+json", - "application/conference-info+xml", - "application/cpl+xml", - "application/csta+xml", - "application/cstadata+xml", - "application/csvm+json", - "application/dart", - "application/dash+xml", - "application/davmount+xml", - "application/dialog-info+xml", - "application/dicom+json", - "application/dicom+xml", - "application/dns+json", - "application/docbook+xml", - "application/dskpp+xml", - "application/dssc+xml", - "application/ecmascript", - "application/elm+json", - "application/elm+xml", - "application/emergencycalldata.cap+xml", - "application/emergencycalldata.comment+xml", - "application/emergencycalldata.control+xml", - "application/emergencycalldata.deviceinfo+xml", - "application/emergencycalldata.providerinfo+xml", - "application/emergencycalldata.serviceinfo+xml", - "application/emergencycalldata.subscriberinfo+xml", - "application/emergencycalldata.veds+xml", - "application/emma+xml", - "application/emotionml+xml", - "application/epp+xml", - "application/expect-ct-report+json", - "application/fdt+xml", - "application/fhir+json", - "application/fhir+xml", - "application/fido.trusted-apps+json", - "application/framework-attributes+xml", - "application/geo+json", - "application/geoxacml+xml", - "application/gml+xml", - "application/gpx+xml", - "application/held+xml", - "application/ibe-key-request+xml", - "application/ibe-pkg-reply+xml", - "application/im-iscomposing+xml", - "application/inkml+xml", - "application/its+xml", - "application/javascript", - "application/jf2feed+json", - "application/jose+json", - "application/jrd+json", - "application/jscalendar+json", - "application/json", - "application/json-patch+json", - "application/jsonml+json", - "application/jwk+json", - "application/jwk-set+json", - "application/kpml-request+xml", - "application/kpml-response+xml", - "application/ld+json", - "application/lgr+xml", - "application/load-control+xml", - "application/lost+xml", - "application/lostsync+xml", - "application/mads+xml", - "application/manifest+json", - "application/marcxml+xml", - "application/mathml+xml", - "application/mathml-content+xml", - "application/mathml-presentation+xml", - "application/mbms-associated-procedure-description+xml", - "application/mbms-deregister+xml", - "application/mbms-envelope+xml", - "application/mbms-msk+xml", - "application/mbms-msk-response+xml", - "application/mbms-protection-description+xml", - "application/mbms-reception-report+xml", - "application/mbms-register+xml", - "application/mbms-register-response+xml", - "application/mbms-schedule+xml", - "application/mbms-user-service-description+xml", - "application/media-policy-dataset+xml", - "application/media_control+xml", - "application/mediaservercontrol+xml", - "application/merge-patch+json", - "application/metalink+xml", - "application/metalink4+xml", - "application/mets+xml", - "application/mmt-aei+xml", - "application/mmt-usd+xml", - "application/mods+xml", - "application/mrb-consumer+xml", - "application/mrb-publish+xml", - "application/msc-ivr+xml", - "application/msc-mixer+xml", - "application/mud+json", - "application/nlsml+xml", - "application/odm+xml", - "application/oebps-package+xml", - "application/omdoc+xml", - "application/opc-nodeset+xml", - "application/p2p-overlay+xml", - "application/patch-ops-error+xml", - "application/pidf+xml", - "application/pidf-diff+xml", - "application/pls+xml", - "application/poc-settings+xml", - "application/postscript", - "application/ppsp-tracker+json", - "application/problem+json", - "application/problem+xml", - "application/provenance+xml", - "application/prs.xsf+xml", - "application/pskc+xml", - "application/pvd+json", - "application/raml+yaml", - "application/rdap+json", - "application/rdf+xml", - "application/reginfo+xml", - "application/reputon+json", - "application/resource-lists+xml", - "application/resource-lists-diff+xml", - "application/rfc+xml", - "application/rlmi+xml", - "application/rls-services+xml", - "application/route-apd+xml", - "application/route-s-tsid+xml", - "application/route-usd+xml", - "application/rsd+xml", - "application/rss+xml", - "application/rtf", - "application/samlassertion+xml", - "application/samlmetadata+xml", - "application/sarif+json", - "application/sarif-external-properties+json", - "application/sbml+xml", - "application/scaip+xml", - "application/scim+json", - "application/senml+json", - "application/senml+xml", - "application/senml-etch+json", - "application/sensml+json", - "application/sensml+xml", - "application/sep+xml", - "application/shf+xml", - "application/simple-filter+xml", - "application/smil+xml", - "application/soap+xml", - "application/sparql-results+xml", - "application/spirits-event+xml", - "application/srgs+xml", - "application/sru+xml", - "application/ssdl+xml", - "application/ssml+xml", - "application/stix+json", - "application/swid+xml", - "application/tar", - "application/taxii+json", - "application/td+json", - "application/tei+xml", - "application/thraud+xml", - "application/tlsrpt+json", - "application/toml", - "application/ttml+xml", - "application/urc-grpsheet+xml", - "application/urc-ressheet+xml", - "application/urc-targetdesc+xml", - "application/urc-uisocketdesc+xml", - "application/vcard+json", - "application/vcard+xml", - "application/vnd.1000minds.decision-model+xml", - "application/vnd.3gpp-prose+xml", - "application/vnd.3gpp-prose-pc3ch+xml", - "application/vnd.3gpp.access-transfer-events+xml", - "application/vnd.3gpp.bsf+xml", - "application/vnd.3gpp.gmop+xml", - "application/vnd.3gpp.mcdata-affiliation-command+xml", - "application/vnd.3gpp.mcdata-info+xml", - "application/vnd.3gpp.mcdata-service-config+xml", - "application/vnd.3gpp.mcdata-ue-config+xml", - "application/vnd.3gpp.mcdata-user-profile+xml", - "application/vnd.3gpp.mcptt-affiliation-command+xml", - "application/vnd.3gpp.mcptt-floor-request+xml", - "application/vnd.3gpp.mcptt-info+xml", - "application/vnd.3gpp.mcptt-location-info+xml", - "application/vnd.3gpp.mcptt-mbms-usage-info+xml", - "application/vnd.3gpp.mcptt-service-config+xml", - "application/vnd.3gpp.mcptt-signed+xml", - "application/vnd.3gpp.mcptt-ue-config+xml", - "application/vnd.3gpp.mcptt-ue-init-config+xml", - "application/vnd.3gpp.mcptt-user-profile+xml", - "application/vnd.3gpp.mcvideo-affiliation-command+xml", - "application/vnd.3gpp.mcvideo-affiliation-info+xml", - "application/vnd.3gpp.mcvideo-info+xml", - "application/vnd.3gpp.mcvideo-location-info+xml", - "application/vnd.3gpp.mcvideo-mbms-usage-info+xml", - "application/vnd.3gpp.mcvideo-service-config+xml", - "application/vnd.3gpp.mcvideo-transmission-request+xml", - "application/vnd.3gpp.mcvideo-ue-config+xml", - "application/vnd.3gpp.mcvideo-user-profile+xml", - "application/vnd.3gpp.mid-call+xml", - "application/vnd.3gpp.sms+xml", - "application/vnd.3gpp.srvcc-ext+xml", - "application/vnd.3gpp.srvcc-info+xml", - "application/vnd.3gpp.state-and-event-info+xml", - "application/vnd.3gpp.ussd+xml", - "application/vnd.3gpp2.bcmcsinfo+xml", - "application/vnd.adobe.xdp+xml", - "application/vnd.amadeus+json", - "application/vnd.amundsen.maze+xml", - "application/vnd.api+json", - "application/vnd.aplextor.warrp+json", - "application/vnd.apothekende.reservation+json", - "application/vnd.apple.installer+xml", - "application/vnd.artisan+json", - "application/vnd.avalon+json", - "application/vnd.avistar+xml", - "application/vnd.balsamiq.bmml+xml", - "application/vnd.bbf.usp.msg+json", - "application/vnd.bekitzur-stech+json", - "application/vnd.biopax.rdf+xml", - "application/vnd.byu.uapi+json", - "application/vnd.capasystems-pg+json", - "application/vnd.chemdraw+xml", - "application/vnd.citationstyles.style+xml", - "application/vnd.collection+json", - "application/vnd.collection.doc+json", - "application/vnd.collection.next+json", - "application/vnd.coreos.ignition+json", - "application/vnd.criticaltools.wbs+xml", - "application/vnd.cryptii.pipe+json", - "application/vnd.ctct.ws+xml", - "application/vnd.cyan.dean.root+xml", - "application/vnd.cyclonedx+json", - "application/vnd.cyclonedx+xml", - "application/vnd.dart", - "application/vnd.datapackage+json", - "application/vnd.dataresource+json", - "application/vnd.dece.ttml+xml", - "application/vnd.dm.delegation+xml", - "application/vnd.document+json", - "application/vnd.drive+json", - "application/vnd.dvb.dvbisl+xml", - "application/vnd.dvb.notif-aggregate-root+xml", - "application/vnd.dvb.notif-container+xml", - "application/vnd.dvb.notif-generic+xml", - "application/vnd.dvb.notif-ia-msglist+xml", - "application/vnd.dvb.notif-ia-registration-request+xml", - "application/vnd.dvb.notif-ia-registration-response+xml", - "application/vnd.dvb.notif-init+xml", - "application/vnd.emclient.accessrequest+xml", - "application/vnd.eprints.data+xml", - "application/vnd.eszigno3+xml", - "application/vnd.etsi.aoc+xml", - "application/vnd.etsi.cug+xml", - "application/vnd.etsi.iptvcommand+xml", - "application/vnd.etsi.iptvdiscovery+xml", - "application/vnd.etsi.iptvprofile+xml", - "application/vnd.etsi.iptvsad-bc+xml", - "application/vnd.etsi.iptvsad-cod+xml", - "application/vnd.etsi.iptvsad-npvr+xml", - "application/vnd.etsi.iptvservice+xml", - "application/vnd.etsi.iptvsync+xml", - "application/vnd.etsi.iptvueprofile+xml", - "application/vnd.etsi.mcid+xml", - "application/vnd.etsi.overload-control-policy-dataset+xml", - "application/vnd.etsi.pstn+xml", - "application/vnd.etsi.sci+xml", - "application/vnd.etsi.simservs+xml", - "application/vnd.etsi.tsl+xml", - "application/vnd.fujifilm.fb.jfi+xml", - "application/vnd.futoin+json", - "application/vnd.gentics.grd+json", - "application/vnd.geo+json", - "application/vnd.geocube+xml", - "application/vnd.google-earth.kml+xml", - "application/vnd.gov.sk.e-form+xml", - "application/vnd.gov.sk.xmldatacontainer+xml", - "application/vnd.hal+json", - "application/vnd.hal+xml", - "application/vnd.handheld-entertainment+xml", - "application/vnd.hc+json", - "application/vnd.heroku+json", - "application/vnd.hyper+json", - "application/vnd.hyper-item+json", - "application/vnd.hyperdrive+json", - "application/vnd.ims.lis.v2.result+json", - "application/vnd.ims.lti.v2.toolconsumerprofile+json", - "application/vnd.ims.lti.v2.toolproxy+json", - "application/vnd.ims.lti.v2.toolproxy.id+json", - "application/vnd.ims.lti.v2.toolsettings+json", - "application/vnd.ims.lti.v2.toolsettings.simple+json", - "application/vnd.informedcontrol.rms+xml", - "application/vnd.infotech.project+xml", - "application/vnd.iptc.g2.catalogitem+xml", - "application/vnd.iptc.g2.conceptitem+xml", - "application/vnd.iptc.g2.knowledgeitem+xml", - "application/vnd.iptc.g2.newsitem+xml", - "application/vnd.iptc.g2.newsmessage+xml", - "application/vnd.iptc.g2.packageitem+xml", - "application/vnd.iptc.g2.planningitem+xml", - "application/vnd.irepository.package+xml", - "application/vnd.las.las+json", - "application/vnd.las.las+xml", - "application/vnd.leap+json", - "application/vnd.liberty-request+xml", - "application/vnd.llamagraphics.life-balance.exchange+xml", - "application/vnd.marlin.drm.actiontoken+xml", - "application/vnd.marlin.drm.conftoken+xml", - "application/vnd.marlin.drm.license+xml", - "application/vnd.mason+json", - "application/vnd.micro+json", - "application/vnd.miele+json", - "application/vnd.mozilla.xul+xml", - "application/vnd.ms-fontobject", - "application/vnd.ms-office.activex+xml", - "application/vnd.ms-opentype", - "application/vnd.ms-playready.initiator+xml", - "application/vnd.ms-printdevicecapabilities+xml", - "application/vnd.ms-printing.printticket+xml", - "application/vnd.ms-printschematicket+xml", - "application/vnd.nearst.inv+json", - "application/vnd.nokia.conml+xml", - "application/vnd.nokia.iptv.config+xml", - "application/vnd.nokia.landmark+xml", - "application/vnd.nokia.landmarkcollection+xml", - "application/vnd.nokia.n-gage.ac+xml", - "application/vnd.nokia.pcd+xml", - "application/vnd.oci.image.manifest.v1+json", - "application/vnd.oftn.l10n+json", - "application/vnd.oipf.contentaccessdownload+xml", - "application/vnd.oipf.contentaccessstreaming+xml", - "application/vnd.oipf.dae.svg+xml", - "application/vnd.oipf.dae.xhtml+xml", - "application/vnd.oipf.mippvcontrolmessage+xml", - "application/vnd.oipf.spdiscovery+xml", - "application/vnd.oipf.spdlist+xml", - "application/vnd.oipf.ueprofile+xml", - "application/vnd.oipf.userprofile+xml", - "application/vnd.oma.bcast.associated-procedure-parameter+xml", - "application/vnd.oma.bcast.drm-trigger+xml", - "application/vnd.oma.bcast.imd+xml", - "application/vnd.oma.bcast.notification+xml", - "application/vnd.oma.bcast.sgdd+xml", - "application/vnd.oma.bcast.smartcard-trigger+xml", - "application/vnd.oma.bcast.sprov+xml", - "application/vnd.oma.cab-address-book+xml", - "application/vnd.oma.cab-feature-handler+xml", - "application/vnd.oma.cab-pcc+xml", - "application/vnd.oma.cab-subs-invite+xml", - "application/vnd.oma.cab-user-prefs+xml", - "application/vnd.oma.dd2+xml", - "application/vnd.oma.drm.risd+xml", - "application/vnd.oma.group-usage-list+xml", - "application/vnd.oma.lwm2m+json", - "application/vnd.oma.pal+xml", - "application/vnd.oma.poc.detailed-progress-report+xml", - "application/vnd.oma.poc.final-report+xml", - "application/vnd.oma.poc.groups+xml", - "application/vnd.oma.poc.invocation-descriptor+xml", - "application/vnd.oma.poc.optimized-progress-report+xml", - "application/vnd.oma.scidm.messages+xml", - "application/vnd.oma.xcap-directory+xml", - "application/vnd.omads-email+xml", - "application/vnd.omads-file+xml", - "application/vnd.omads-folder+xml", - "application/vnd.openblox.game+xml", - "application/vnd.openstreetmap.data+xml", - "application/vnd.openxmlformats-officedocument.custom-properties+xml", - "application/vnd.openxmlformats-officedocument.customxmlproperties+xml", - "application/vnd.openxmlformats-officedocument.drawing+xml", - "application/vnd.openxmlformats-officedocument.drawingml.chart+xml", - "application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml", - "application/vnd.openxmlformats-officedocument.drawingml.diagramcolors+xml", - "application/vnd.openxmlformats-officedocument.drawingml.diagramdata+xml", - "application/vnd.openxmlformats-officedocument.drawingml.diagramlayout+xml", - "application/vnd.openxmlformats-officedocument.drawingml.diagramstyle+xml", - "application/vnd.openxmlformats-officedocument.extended-properties+xml", - "application/vnd.openxmlformats-officedocument.presentationml.commentauthors+xml", - "application/vnd.openxmlformats-officedocument.presentationml.comments+xml", - "application/vnd.openxmlformats-officedocument.presentationml.handoutmaster+xml", - "application/vnd.openxmlformats-officedocument.presentationml.notesmaster+xml", - "application/vnd.openxmlformats-officedocument.presentationml.notesslide+xml", - "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml", - "application/vnd.openxmlformats-officedocument.presentationml.presprops+xml", - "application/vnd.openxmlformats-officedocument.presentationml.slide+xml", - "application/vnd.openxmlformats-officedocument.presentationml.slidelayout+xml", - "application/vnd.openxmlformats-officedocument.presentationml.slidemaster+xml", - "application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml", - "application/vnd.openxmlformats-officedocument.presentationml.slideupdateinfo+xml", - "application/vnd.openxmlformats-officedocument.presentationml.tablestyles+xml", - "application/vnd.openxmlformats-officedocument.presentationml.tags+xml", - "application/vnd.openxmlformats-officedocument.presentationml.template.main+xml", - "application/vnd.openxmlformats-officedocument.presentationml.viewprops+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.calcchain+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.externallink+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotcachedefinition+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotcacherecords+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.pivottable+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.querytable+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.revisionheaders+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.revisionlog+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedstrings+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheetmetadata+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.tablesinglecells+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.usernames+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.volatiledependencies+xml", - "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml", - "application/vnd.openxmlformats-officedocument.theme+xml", - "application/vnd.openxmlformats-officedocument.themeoverride+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.fonttable+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml", - "application/vnd.openxmlformats-officedocument.wordprocessingml.websettings+xml", - "application/vnd.openxmlformats-package.core-properties+xml", - "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml", - "application/vnd.openxmlformats-package.relationships+xml", - "application/vnd.oracle.resource+json", - "application/vnd.otps.ct-kip+xml", - "application/vnd.pagerduty+json", - "application/vnd.poc.group-advertisement+xml", - "application/vnd.pwg-xhtml-print+xml", - "application/vnd.radisys.moml+xml", - "application/vnd.radisys.msml+xml", - "application/vnd.radisys.msml-audit+xml", - "application/vnd.radisys.msml-audit-conf+xml", - "application/vnd.radisys.msml-audit-conn+xml", - "application/vnd.radisys.msml-audit-dialog+xml", - "application/vnd.radisys.msml-audit-stream+xml", - "application/vnd.radisys.msml-conf+xml", - "application/vnd.radisys.msml-dialog+xml", - "application/vnd.radisys.msml-dialog-base+xml", - "application/vnd.radisys.msml-dialog-fax-detect+xml", - "application/vnd.radisys.msml-dialog-fax-sendrecv+xml", - "application/vnd.radisys.msml-dialog-group+xml", - "application/vnd.radisys.msml-dialog-speech+xml", - "application/vnd.radisys.msml-dialog-transform+xml", - "application/vnd.recordare.musicxml+xml", - "application/vnd.restful+json", - "application/vnd.route66.link66+xml", - "application/vnd.seis+json", - "application/vnd.shootproof+json", - "application/vnd.shopkick+json", - "application/vnd.siren+json", - "application/vnd.software602.filler.form+xml", - "application/vnd.solent.sdkm+xml", - "application/vnd.sun.wadl+xml", - "application/vnd.sycle+xml", - "application/vnd.syncml+xml", - "application/vnd.syncml.dm+xml", - "application/vnd.syncml.dmddf+xml", - "application/vnd.syncml.dmtnds+xml", - "application/vnd.tableschema+json", - "application/vnd.think-cell.ppttc+json", - "application/vnd.tmd.mediaflex.api+xml", - "application/vnd.uoml+xml", - "application/vnd.vel+json", - "application/vnd.wv.csp+xml", - "application/vnd.wv.ssp+xml", - "application/vnd.xacml+json", - "application/vnd.xmi+xml", - "application/vnd.yamaha.openscoreformat.osfpvg+xml", - "application/vnd.zzazz.deck+xml", - "application/voicexml+xml", - "application/voucher-cms+json", - "application/wasm", - "application/watcherinfo+xml", - "application/webpush-options+json", - "application/wsdl+xml", - "application/wspolicy+xml", - "application/x-dtbncx+xml", - "application/x-dtbook+xml", - "application/x-dtbresource+xml", - "application/x-httpd-php", - "application/x-javascript", - "application/x-ns-proxy-autoconfig", - "application/x-sh", - "application/x-tar", - "application/x-virtualbox-hdd", - "application/x-virtualbox-ova", - "application/x-virtualbox-ovf", - "application/x-virtualbox-vbox", - "application/x-virtualbox-vdi", - "application/x-virtualbox-vhd", - "application/x-virtualbox-vmdk", - "application/x-web-app-manifest+json", - "application/x-www-form-urlencoded", - "application/x-xliff+xml", - "application/xacml+xml", - "application/xaml+xml", - "application/xcap-att+xml", - "application/xcap-caps+xml", - "application/xcap-diff+xml", - "application/xcap-el+xml", - "application/xcap-error+xml", - "application/xcap-ns+xml", - "application/xcon-conference-info+xml", - "application/xcon-conference-info-diff+xml", - "application/xenc+xml", - "application/xhtml+xml", - "application/xhtml-voice+xml", - "application/xliff+xml", - "application/xml", - "application/xml-dtd", - "application/xml-patch+xml", - "application/xmpp+xml", - "application/xop+xml", - "application/xproc+xml", - "application/xslt+xml", - "application/xspf+xml", - "application/xv+xml", - "application/yang-data+json", - "application/yang-data+xml", - "application/yang-patch+json", - "application/yang-patch+xml", - "application/yin+xml", - "font/otf", - "font/ttf", - "image/bmp", - "image/svg+xml", - "image/vnd.adobe.photoshop", - "image/x-icon", - "image/x-ms-bmp", - "message/imdn+xml", - "message/rfc822", - "model/gltf+json", - "model/gltf-binary", - "model/vnd.collada+xml", - "model/vnd.moml+xml", - "model/x3d+xml", - "text/cache-manifest", - "text/calender", - "text/cmd", - "text/css", - "text/csv", - "text/html", - "text/javascript", - "text/jsx", - "text/less", - "text/markdown", - "text/mdx", - "text/n3", - "text/plain", - "text/richtext", - "text/rtf", - "text/tab-separated-values", - "text/uri-list", - "text/vcard", - "text/vtt", - "text/x-gwt-rpc", - "text/x-jquery-tmpl", - "text/x-markdown", - "text/x-org", - "text/x-processing", - "text/x-suse-ymp", - "text/xml", - "text/yaml", - "x-shader/x-fragment", - "x-shader/x-vertex", -]; +static CONTENT_TYPES: phf::Set<&'static [u8]> = phf_set! { + b"application/3gpdash-qoe-report+xml", + b"application/3gpp-ims+xml", + b"application/3gpphal+json", + b"application/3gpphalforms+json", + b"application/activity+json", + b"application/alto-costmap+json", + b"application/alto-costmapfilter+json", + b"application/alto-directory+json", + b"application/alto-endpointcost+json", + b"application/alto-endpointcostparams+json", + b"application/alto-endpointprop+json", + b"application/alto-endpointpropparams+json", + b"application/alto-error+json", + b"application/alto-networkmap+json", + b"application/alto-networkmapfilter+json", + b"application/alto-updatestreamcontrol+json", + b"application/alto-updatestreamparams+json", + b"application/atom+xml", + b"application/atomcat+xml", + b"application/atomdeleted+xml", + b"application/atomsvc+xml", + b"application/atsc-dwd+xml", + b"application/atsc-held+xml", + b"application/atsc-rdt+json", + b"application/atsc-rsat+xml", + b"application/auth-policy+xml", + b"application/beep+xml", + b"application/calendar+json", + b"application/calendar+xml", + b"application/captive+json", + b"application/ccmp+xml", + b"application/ccxml+xml", + b"application/cdfx+xml", + b"application/cea-2018+xml", + b"application/cellml+xml", + b"application/clue+xml", + b"application/clue_info+xml", + b"application/cnrp+xml", + b"application/coap-group+json", + b"application/conference-info+xml", + b"application/cpl+xml", + b"application/csta+xml", + b"application/cstadata+xml", + b"application/csvm+json", + b"application/dart", + b"application/dash+xml", + b"application/davmount+xml", + b"application/dialog-info+xml", + b"application/dicom+json", + b"application/dicom+xml", + b"application/dns+json", + b"application/docbook+xml", + b"application/dskpp+xml", + b"application/dssc+xml", + b"application/ecmascript", + b"application/elm+json", + b"application/elm+xml", + b"application/emergencycalldata.cap+xml", + b"application/emergencycalldata.comment+xml", + b"application/emergencycalldata.control+xml", + b"application/emergencycalldata.deviceinfo+xml", + b"application/emergencycalldata.providerinfo+xml", + b"application/emergencycalldata.serviceinfo+xml", + b"application/emergencycalldata.subscriberinfo+xml", + b"application/emergencycalldata.veds+xml", + b"application/emma+xml", + b"application/emotionml+xml", + b"application/epp+xml", + b"application/expect-ct-report+json", + b"application/fdt+xml", + b"application/fhir+json", + b"application/fhir+xml", + b"application/fido.trusted-apps+json", + b"application/framework-attributes+xml", + b"application/geo+json", + b"application/geoxacml+xml", + b"application/gml+xml", + b"application/gpx+xml", + b"application/held+xml", + b"application/ibe-key-request+xml", + b"application/ibe-pkg-reply+xml", + b"application/im-iscomposing+xml", + b"application/inkml+xml", + b"application/its+xml", + b"application/javascript", + b"application/jf2feed+json", + b"application/jose+json", + b"application/jrd+json", + b"application/jscalendar+json", + b"application/json", + b"application/json-patch+json", + b"application/jsonml+json", + b"application/jwk+json", + b"application/jwk-set+json", + b"application/kpml-request+xml", + b"application/kpml-response+xml", + b"application/ld+json", + b"application/lgr+xml", + b"application/load-control+xml", + b"application/lost+xml", + b"application/lostsync+xml", + b"application/mads+xml", + b"application/manifest+json", + b"application/marcxml+xml", + b"application/mathml+xml", + b"application/mathml-content+xml", + b"application/mathml-presentation+xml", + b"application/mbms-associated-procedure-description+xml", + b"application/mbms-deregister+xml", + b"application/mbms-envelope+xml", + b"application/mbms-msk+xml", + b"application/mbms-msk-response+xml", + b"application/mbms-protection-description+xml", + b"application/mbms-reception-report+xml", + b"application/mbms-register+xml", + b"application/mbms-register-response+xml", + b"application/mbms-schedule+xml", + b"application/mbms-user-service-description+xml", + b"application/media-policy-dataset+xml", + b"application/media_control+xml", + b"application/mediaservercontrol+xml", + b"application/merge-patch+json", + b"application/metalink+xml", + b"application/metalink4+xml", + b"application/mets+xml", + b"application/mmt-aei+xml", + b"application/mmt-usd+xml", + b"application/mods+xml", + b"application/mrb-consumer+xml", + b"application/mrb-publish+xml", + b"application/msc-ivr+xml", + b"application/msc-mixer+xml", + b"application/mud+json", + b"application/nlsml+xml", + b"application/odm+xml", + b"application/oebps-package+xml", + b"application/omdoc+xml", + b"application/opc-nodeset+xml", + b"application/p2p-overlay+xml", + b"application/patch-ops-error+xml", + b"application/pidf+xml", + b"application/pidf-diff+xml", + b"application/pls+xml", + b"application/poc-settings+xml", + b"application/postscript", + b"application/ppsp-tracker+json", + b"application/problem+json", + b"application/problem+xml", + b"application/provenance+xml", + b"application/prs.xsf+xml", + b"application/pskc+xml", + b"application/pvd+json", + b"application/raml+yaml", + b"application/rdap+json", + b"application/rdf+xml", + b"application/reginfo+xml", + b"application/reputon+json", + b"application/resource-lists+xml", + b"application/resource-lists-diff+xml", + b"application/rfc+xml", + b"application/rlmi+xml", + b"application/rls-services+xml", + b"application/route-apd+xml", + b"application/route-s-tsid+xml", + b"application/route-usd+xml", + b"application/rsd+xml", + b"application/rss+xml", + b"application/rtf", + b"application/samlassertion+xml", + b"application/samlmetadata+xml", + b"application/sarif+json", + b"application/sarif-external-properties+json", + b"application/sbml+xml", + b"application/scaip+xml", + b"application/scim+json", + b"application/senml+json", + b"application/senml+xml", + b"application/senml-etch+json", + b"application/sensml+json", + b"application/sensml+xml", + b"application/sep+xml", + b"application/shf+xml", + b"application/simple-filter+xml", + b"application/smil+xml", + b"application/soap+xml", + b"application/sparql-results+xml", + b"application/spirits-event+xml", + b"application/srgs+xml", + b"application/sru+xml", + b"application/ssdl+xml", + b"application/ssml+xml", + b"application/stix+json", + b"application/swid+xml", + b"application/tar", + b"application/taxii+json", + b"application/td+json", + b"application/tei+xml", + b"application/thraud+xml", + b"application/tlsrpt+json", + b"application/toml", + b"application/ttml+xml", + b"application/urc-grpsheet+xml", + b"application/urc-ressheet+xml", + b"application/urc-targetdesc+xml", + b"application/urc-uisocketdesc+xml", + b"application/vcard+json", + b"application/vcard+xml", + b"application/vnd.1000minds.decision-model+xml", + b"application/vnd.3gpp-prose+xml", + b"application/vnd.3gpp-prose-pc3ch+xml", + b"application/vnd.3gpp.access-transfer-events+xml", + b"application/vnd.3gpp.bsf+xml", + b"application/vnd.3gpp.gmop+xml", + b"application/vnd.3gpp.mcdata-affiliation-command+xml", + b"application/vnd.3gpp.mcdata-info+xml", + b"application/vnd.3gpp.mcdata-service-config+xml", + b"application/vnd.3gpp.mcdata-ue-config+xml", + b"application/vnd.3gpp.mcdata-user-profile+xml", + b"application/vnd.3gpp.mcptt-affiliation-command+xml", + b"application/vnd.3gpp.mcptt-floor-request+xml", + b"application/vnd.3gpp.mcptt-info+xml", + b"application/vnd.3gpp.mcptt-location-info+xml", + b"application/vnd.3gpp.mcptt-mbms-usage-info+xml", + b"application/vnd.3gpp.mcptt-service-config+xml", + b"application/vnd.3gpp.mcptt-signed+xml", + b"application/vnd.3gpp.mcptt-ue-config+xml", + b"application/vnd.3gpp.mcptt-ue-init-config+xml", + b"application/vnd.3gpp.mcptt-user-profile+xml", + b"application/vnd.3gpp.mcvideo-affiliation-command+xml", + b"application/vnd.3gpp.mcvideo-affiliation-info+xml", + b"application/vnd.3gpp.mcvideo-info+xml", + b"application/vnd.3gpp.mcvideo-location-info+xml", + b"application/vnd.3gpp.mcvideo-mbms-usage-info+xml", + b"application/vnd.3gpp.mcvideo-service-config+xml", + b"application/vnd.3gpp.mcvideo-transmission-request+xml", + b"application/vnd.3gpp.mcvideo-ue-config+xml", + b"application/vnd.3gpp.mcvideo-user-profile+xml", + b"application/vnd.3gpp.mid-call+xml", + b"application/vnd.3gpp.sms+xml", + b"application/vnd.3gpp.srvcc-ext+xml", + b"application/vnd.3gpp.srvcc-info+xml", + b"application/vnd.3gpp.state-and-event-info+xml", + b"application/vnd.3gpp.ussd+xml", + b"application/vnd.3gpp2.bcmcsinfo+xml", + b"application/vnd.adobe.xdp+xml", + b"application/vnd.amadeus+json", + b"application/vnd.amundsen.maze+xml", + b"application/vnd.api+json", + b"application/vnd.aplextor.warrp+json", + b"application/vnd.apothekende.reservation+json", + b"application/vnd.apple.installer+xml", + b"application/vnd.artisan+json", + b"application/vnd.avalon+json", + b"application/vnd.avistar+xml", + b"application/vnd.balsamiq.bmml+xml", + b"application/vnd.bbf.usp.msg+json", + b"application/vnd.bekitzur-stech+json", + b"application/vnd.biopax.rdf+xml", + b"application/vnd.byu.uapi+json", + b"application/vnd.capasystems-pg+json", + b"application/vnd.chemdraw+xml", + b"application/vnd.citationstyles.style+xml", + b"application/vnd.collection+json", + b"application/vnd.collection.doc+json", + b"application/vnd.collection.next+json", + b"application/vnd.coreos.ignition+json", + b"application/vnd.criticaltools.wbs+xml", + b"application/vnd.cryptii.pipe+json", + b"application/vnd.ctct.ws+xml", + b"application/vnd.cyan.dean.root+xml", + b"application/vnd.cyclonedx+json", + b"application/vnd.cyclonedx+xml", + b"application/vnd.dart", + b"application/vnd.datapackage+json", + b"application/vnd.dataresource+json", + b"application/vnd.dece.ttml+xml", + b"application/vnd.dm.delegation+xml", + b"application/vnd.document+json", + b"application/vnd.drive+json", + b"application/vnd.dvb.dvbisl+xml", + b"application/vnd.dvb.notif-aggregate-root+xml", + b"application/vnd.dvb.notif-container+xml", + b"application/vnd.dvb.notif-generic+xml", + b"application/vnd.dvb.notif-ia-msglist+xml", + b"application/vnd.dvb.notif-ia-registration-request+xml", + b"application/vnd.dvb.notif-ia-registration-response+xml", + b"application/vnd.dvb.notif-init+xml", + b"application/vnd.emclient.accessrequest+xml", + b"application/vnd.eprints.data+xml", + b"application/vnd.eszigno3+xml", + b"application/vnd.etsi.aoc+xml", + b"application/vnd.etsi.cug+xml", + b"application/vnd.etsi.iptvcommand+xml", + b"application/vnd.etsi.iptvdiscovery+xml", + b"application/vnd.etsi.iptvprofile+xml", + b"application/vnd.etsi.iptvsad-bc+xml", + b"application/vnd.etsi.iptvsad-cod+xml", + b"application/vnd.etsi.iptvsad-npvr+xml", + b"application/vnd.etsi.iptvservice+xml", + b"application/vnd.etsi.iptvsync+xml", + b"application/vnd.etsi.iptvueprofile+xml", + b"application/vnd.etsi.mcid+xml", + b"application/vnd.etsi.overload-control-policy-dataset+xml", + b"application/vnd.etsi.pstn+xml", + b"application/vnd.etsi.sci+xml", + b"application/vnd.etsi.simservs+xml", + b"application/vnd.etsi.tsl+xml", + b"application/vnd.fujifilm.fb.jfi+xml", + b"application/vnd.futoin+json", + b"application/vnd.gentics.grd+json", + b"application/vnd.geo+json", + b"application/vnd.geocube+xml", + b"application/vnd.google-earth.kml+xml", + b"application/vnd.gov.sk.e-form+xml", + b"application/vnd.gov.sk.xmldatacontainer+xml", + b"application/vnd.hal+json", + b"application/vnd.hal+xml", + b"application/vnd.handheld-entertainment+xml", + b"application/vnd.hc+json", + b"application/vnd.heroku+json", + b"application/vnd.hyper+json", + b"application/vnd.hyper-item+json", + b"application/vnd.hyperdrive+json", + b"application/vnd.ims.lis.v2.result+json", + b"application/vnd.ims.lti.v2.toolconsumerprofile+json", + b"application/vnd.ims.lti.v2.toolproxy+json", + b"application/vnd.ims.lti.v2.toolproxy.id+json", + b"application/vnd.ims.lti.v2.toolsettings+json", + b"application/vnd.ims.lti.v2.toolsettings.simple+json", + b"application/vnd.informedcontrol.rms+xml", + b"application/vnd.infotech.project+xml", + b"application/vnd.iptc.g2.catalogitem+xml", + b"application/vnd.iptc.g2.conceptitem+xml", + b"application/vnd.iptc.g2.knowledgeitem+xml", + b"application/vnd.iptc.g2.newsitem+xml", + b"application/vnd.iptc.g2.newsmessage+xml", + b"application/vnd.iptc.g2.packageitem+xml", + b"application/vnd.iptc.g2.planningitem+xml", + b"application/vnd.irepository.package+xml", + b"application/vnd.las.las+json", + b"application/vnd.las.las+xml", + b"application/vnd.leap+json", + b"application/vnd.liberty-request+xml", + b"application/vnd.llamagraphics.life-balance.exchange+xml", + b"application/vnd.marlin.drm.actiontoken+xml", + b"application/vnd.marlin.drm.conftoken+xml", + b"application/vnd.marlin.drm.license+xml", + b"application/vnd.mason+json", + b"application/vnd.micro+json", + b"application/vnd.miele+json", + b"application/vnd.mozilla.xul+xml", + b"application/vnd.ms-fontobject", + b"application/vnd.ms-office.activex+xml", + b"application/vnd.ms-opentype", + b"application/vnd.ms-playready.initiator+xml", + b"application/vnd.ms-printdevicecapabilities+xml", + b"application/vnd.ms-printing.printticket+xml", + b"application/vnd.ms-printschematicket+xml", + b"application/vnd.nearst.inv+json", + b"application/vnd.nokia.conml+xml", + b"application/vnd.nokia.iptv.config+xml", + b"application/vnd.nokia.landmark+xml", + b"application/vnd.nokia.landmarkcollection+xml", + b"application/vnd.nokia.n-gage.ac+xml", + b"application/vnd.nokia.pcd+xml", + b"application/vnd.oci.image.manifest.v1+json", + b"application/vnd.oftn.l10n+json", + b"application/vnd.oipf.contentaccessdownload+xml", + b"application/vnd.oipf.contentaccessstreaming+xml", + b"application/vnd.oipf.dae.svg+xml", + b"application/vnd.oipf.dae.xhtml+xml", + b"application/vnd.oipf.mippvcontrolmessage+xml", + b"application/vnd.oipf.spdiscovery+xml", + b"application/vnd.oipf.spdlist+xml", + b"application/vnd.oipf.ueprofile+xml", + b"application/vnd.oipf.userprofile+xml", + b"application/vnd.oma.bcast.associated-procedure-parameter+xml", + b"application/vnd.oma.bcast.drm-trigger+xml", + b"application/vnd.oma.bcast.imd+xml", + b"application/vnd.oma.bcast.notification+xml", + b"application/vnd.oma.bcast.sgdd+xml", + b"application/vnd.oma.bcast.smartcard-trigger+xml", + b"application/vnd.oma.bcast.sprov+xml", + b"application/vnd.oma.cab-address-book+xml", + b"application/vnd.oma.cab-feature-handler+xml", + b"application/vnd.oma.cab-pcc+xml", + b"application/vnd.oma.cab-subs-invite+xml", + b"application/vnd.oma.cab-user-prefs+xml", + b"application/vnd.oma.dd2+xml", + b"application/vnd.oma.drm.risd+xml", + b"application/vnd.oma.group-usage-list+xml", + b"application/vnd.oma.lwm2m+json", + b"application/vnd.oma.pal+xml", + b"application/vnd.oma.poc.detailed-progress-report+xml", + b"application/vnd.oma.poc.final-report+xml", + b"application/vnd.oma.poc.groups+xml", + b"application/vnd.oma.poc.invocation-descriptor+xml", + b"application/vnd.oma.poc.optimized-progress-report+xml", + b"application/vnd.oma.scidm.messages+xml", + b"application/vnd.oma.xcap-directory+xml", + b"application/vnd.omads-email+xml", + b"application/vnd.omads-file+xml", + b"application/vnd.omads-folder+xml", + b"application/vnd.openblox.game+xml", + b"application/vnd.openstreetmap.data+xml", + b"application/vnd.openxmlformats-officedocument.custom-properties+xml", + b"application/vnd.openxmlformats-officedocument.customxmlproperties+xml", + b"application/vnd.openxmlformats-officedocument.drawing+xml", + b"application/vnd.openxmlformats-officedocument.drawingml.chart+xml", + b"application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml", + b"application/vnd.openxmlformats-officedocument.drawingml.diagramcolors+xml", + b"application/vnd.openxmlformats-officedocument.drawingml.diagramdata+xml", + b"application/vnd.openxmlformats-officedocument.drawingml.diagramlayout+xml", + b"application/vnd.openxmlformats-officedocument.drawingml.diagramstyle+xml", + b"application/vnd.openxmlformats-officedocument.extended-properties+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.commentauthors+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.comments+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.handoutmaster+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.notesmaster+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.notesslide+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.presprops+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.slide+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.slidelayout+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.slidemaster+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.slideupdateinfo+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.tablestyles+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.tags+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.template.main+xml", + b"application/vnd.openxmlformats-officedocument.presentationml.viewprops+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.calcchain+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.externallink+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotcachedefinition+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotcacherecords+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.pivottable+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.querytable+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.revisionheaders+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.revisionlog+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedstrings+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetmetadata+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.tablesinglecells+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.usernames+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.volatiledependencies+xml", + b"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml", + b"application/vnd.openxmlformats-officedocument.theme+xml", + b"application/vnd.openxmlformats-officedocument.themeoverride+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.fonttable+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml", + b"application/vnd.openxmlformats-officedocument.wordprocessingml.websettings+xml", + b"application/vnd.openxmlformats-package.core-properties+xml", + b"application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml", + b"application/vnd.openxmlformats-package.relationships+xml", + b"application/vnd.oracle.resource+json", + b"application/vnd.otps.ct-kip+xml", + b"application/vnd.pagerduty+json", + b"application/vnd.poc.group-advertisement+xml", + b"application/vnd.pwg-xhtml-print+xml", + b"application/vnd.radisys.moml+xml", + b"application/vnd.radisys.msml+xml", + b"application/vnd.radisys.msml-audit+xml", + b"application/vnd.radisys.msml-audit-conf+xml", + b"application/vnd.radisys.msml-audit-conn+xml", + b"application/vnd.radisys.msml-audit-dialog+xml", + b"application/vnd.radisys.msml-audit-stream+xml", + b"application/vnd.radisys.msml-conf+xml", + b"application/vnd.radisys.msml-dialog+xml", + b"application/vnd.radisys.msml-dialog-base+xml", + b"application/vnd.radisys.msml-dialog-fax-detect+xml", + b"application/vnd.radisys.msml-dialog-fax-sendrecv+xml", + b"application/vnd.radisys.msml-dialog-group+xml", + b"application/vnd.radisys.msml-dialog-speech+xml", + b"application/vnd.radisys.msml-dialog-transform+xml", + b"application/vnd.recordare.musicxml+xml", + b"application/vnd.restful+json", + b"application/vnd.route66.link66+xml", + b"application/vnd.seis+json", + b"application/vnd.shootproof+json", + b"application/vnd.shopkick+json", + b"application/vnd.siren+json", + b"application/vnd.software602.filler.form+xml", + b"application/vnd.solent.sdkm+xml", + b"application/vnd.sun.wadl+xml", + b"application/vnd.sycle+xml", + b"application/vnd.syncml+xml", + b"application/vnd.syncml.dm+xml", + b"application/vnd.syncml.dmddf+xml", + b"application/vnd.syncml.dmtnds+xml", + b"application/vnd.tableschema+json", + b"application/vnd.think-cell.ppttc+json", + b"application/vnd.tmd.mediaflex.api+xml", + b"application/vnd.uoml+xml", + b"application/vnd.vel+json", + b"application/vnd.wv.csp+xml", + b"application/vnd.wv.ssp+xml", + b"application/vnd.xacml+json", + b"application/vnd.xmi+xml", + b"application/vnd.yamaha.openscoreformat.osfpvg+xml", + b"application/vnd.zzazz.deck+xml", + b"application/voicexml+xml", + b"application/voucher-cms+json", + b"application/wasm", + b"application/watcherinfo+xml", + b"application/webpush-options+json", + b"application/wsdl+xml", + b"application/wspolicy+xml", + b"application/x-dtbncx+xml", + b"application/x-dtbook+xml", + b"application/x-dtbresource+xml", + b"application/x-httpd-php", + b"application/x-javascript", + b"application/x-ns-proxy-autoconfig", + b"application/x-sh", + b"application/x-tar", + b"application/x-virtualbox-hdd", + b"application/x-virtualbox-ova", + b"application/x-virtualbox-ovf", + b"application/x-virtualbox-vbox", + b"application/x-virtualbox-vdi", + b"application/x-virtualbox-vhd", + b"application/x-virtualbox-vmdk", + b"application/x-web-app-manifest+json", + b"application/x-www-form-urlencoded", + b"application/x-xliff+xml", + b"application/xacml+xml", + b"application/xaml+xml", + b"application/xcap-att+xml", + b"application/xcap-caps+xml", + b"application/xcap-diff+xml", + b"application/xcap-el+xml", + b"application/xcap-error+xml", + b"application/xcap-ns+xml", + b"application/xcon-conference-info+xml", + b"application/xcon-conference-info-diff+xml", + b"application/xenc+xml", + b"application/xhtml+xml", + b"application/xhtml-voice+xml", + b"application/xliff+xml", + b"application/xml", + b"application/xml-dtd", + b"application/xml-patch+xml", + b"application/xmpp+xml", + b"application/xop+xml", + b"application/xproc+xml", + b"application/xslt+xml", + b"application/xspf+xml", + b"application/xv+xml", + b"application/yang-data+json", + b"application/yang-data+xml", + b"application/yang-patch+json", + b"application/yang-patch+xml", + b"application/yin+xml", + b"font/otf", + b"font/ttf", + b"image/bmp", + b"image/svg+xml", + b"image/vnd.adobe.photoshop", + b"image/x-icon", + b"image/x-ms-bmp", + b"message/imdn+xml", + b"message/rfc822", + b"model/gltf+json", + b"model/gltf-binary", + b"model/vnd.collada+xml", + b"model/vnd.moml+xml", + b"model/x3d+xml", + b"text/cache-manifest", + b"text/calender", + b"text/cmd", + b"text/css", + b"text/csv", + b"text/html", + b"text/javascript", + b"text/jsx", + b"text/less", + b"text/markdown", + b"text/mdx", + b"text/n3", + b"text/plain", + b"text/richtext", + b"text/rtf", + b"text/tab-separated-values", + b"text/uri-list", + b"text/vcard", + b"text/vtt", + b"text/x-gwt-rpc", + b"text/x-jquery-tmpl", + b"text/x-markdown", + b"text/x-org", + b"text/x-processing", + b"text/x-suse-ymp", + b"text/xml", + b"text/yaml", + b"x-shader/x-fragment", + b"x-shader/x-vertex", +}; + +fn known_compressible(ct: &[u8]) -> bool { + CONTENT_TYPES.contains(ct) +} + +fn known_mime(ct: &[u8]) -> Option { + let s = std::str::from_utf8(ct).ok()?; + let m = mime::Mime::from_str(s).ok()?; + Some(known_compressible(m.essence_str().as_bytes())) +} /// Determine if the supplied content type is considered compressible -pub fn is_content_compressible( - maybe_content_type: Option<&ByteString>, -) -> bool { - if let Some(content_type) = maybe_content_type { - if let Ok(content_type) = std::str::from_utf8(content_type.as_ref()) { - if let Ok(content_type) = content_type.parse::() { - return CONTENT_TYPES - .binary_search(&content_type.essence_str()) - .is_ok(); - } - } - } - false +pub fn is_content_compressible(ct: impl AsRef<[u8]>) -> bool { + let ct = ct.as_ref(); + let prefix = ct.split(|c| *c == b';').next().unwrap(); + known_compressible(prefix) || known_mime(prefix).unwrap_or_default() } #[cfg(test)] mod tests { use super::*; - #[test] - fn content_type_none() { - assert!(!is_content_compressible(None)); - } - #[test] fn non_compressible_content_type() { - assert!(!is_content_compressible(Some( - &"application/vnd.deno+json".into() - ))); + assert!(!is_content_compressible("application/vnd.deno+json")); + assert!(!is_content_compressible("text/fake")); } #[test] - fn ncompressible_content_type() { - assert!(is_content_compressible(Some(&"application/json".into()))); + fn compressible_content_type() { + assert!(is_content_compressible("application/json")); + assert!(is_content_compressible("text/plain;charset=UTF-8")); + assert!(is_content_compressible("text/PlAIn; charset=utf-8")); } } diff --git a/ext/http/lib.rs b/ext/http/lib.rs index 4911c543b9..1888409ba6 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -65,7 +65,7 @@ use tokio::io::AsyncWriteExt; use tokio::task::spawn_local; use tokio_util::io::ReaderStream; -mod compressible; +pub mod compressible; pub fn init() -> Extension { Extension::builder() @@ -542,8 +542,9 @@ async fn op_http_write_headers( } if headers_allow_compression { - body_compressible = - compressible::is_content_compressible(content_type_header); + body_compressible = content_type_header + .map(compressible::is_content_compressible) + .unwrap_or_default(); } let body: Response;