Skip to content

Commit

Permalink
Add temporary warning to blob.c++ to see if MimeType can be used
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Jul 5, 2023
1 parent ac3256c commit a42e996
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/workerd/api/blob.c++
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "blob.h"
#include "streams.h"
#include "util.h"
#include <workerd/util/mimetype.h>

namespace workerd::api {

Expand Down Expand Up @@ -59,6 +60,18 @@ static kj::Array<byte> concat(jsg::Optional<Blob::Bits> maybeBits) {
}

static kj::String normalizeType(kj::String type) {
// TODO(soon): Add temporary logging if the type is not a valid mime type.
// This does not properly parse mime types. We have the new workerd::MimeType impl
// but that handles mime types a bit more strictly than this. We can/should switch
// over to it but there's a non-zero risk of breaking running code. We might need
// a compat flag to switch. To know for sure, we temporarily add logging here to
// see if anyone in the wild is relying on the incorrect parsing.
// If we see this log even once in production then we cannot switch normalizeType
// for MimeType::tryParse without a compatibility flag.
if (MimeType::tryParse(type) == nullptr) {
LOG_WARNING_ONCE("Blob created with invalid/unparseable content type");
}

// https://www.w3.org/TR/FileAPI/#constructorBlob step 3 inexplicably insists that if the
// type contains non-printable-ASCII characters we should discard it, and otherwise we should
// lower-case it.
Expand Down

0 comments on commit a42e996

Please # to comment.