GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Handling missing mime types gracefully · Issue #534 · CrowCpp/Crow

Handling missing mime types gracefully #534

New issue
Copy link
New issue
Copy link
Closed
Closed
Handling missing mime types gracefully#534
Copy link
Assignees
jake-arkinstall
Labels
featureCode based project improvementgood first issuean issue suitable to start contributing to the project

Description

@jake-arkinstall
jake-arkinstall
opened on Sep 10, 2022
Issue body actions

If a key isn't present in the mime_types map, an exception is thrown. This is because mime_types.at() is used at, e.g.,

Crow/include/crow/http_response.h

Line 104 in c0bfaa7

set_header("Content-Type", mime_types.at(contentType));
.

I propose that the resolution is to search for the provided mime_type within the map using mime_types.find. If it is not found, a warning should be logged, but the content should still be delivered using the following logic:

  • Does the provided type look like a MIME type already? I.e. is it one of the IANA-registered types (application, audio, example, font, image, model, text, video), followed by a slash, followed by text? If so, send that verbatim.

  • Otherwise send text/plain.

Although this approach isn't quite as lightweight as simply sending text/plain, there are some benefits:

  • I'd be able, for example, to send content as text/csv without modifying the mime types map.
  • It would also allow people to use the full mime-type format, including parameters (e.g. text/plain;charset=UTF-8)
  • Developers coming from other technologies that use full mime types won't be faced with an internal server error for following an old habit.

Activity

  1. dranikpg commented on Sep 10, 2022

    @dranikpg
    dranikpg
    on Sep 10, 2022
    Member
    More actions

    I fully agree, the current solution is way to limited. If you need to construct custom mime-types now, you can always set the Content-Type header yourself. But this feels like a workaround.

    Jake, if you want, you can implement the fix youself and make your first contribution to Crow! 🔥

    Else, I'll handle this in the following week.

  2. dranikpg
    added
    featureCode based project improvement
    good first issuean issue suitable to start contributing to the project
    on Sep 10, 2022
  3. dranikpg
    assigned
    jake-arkinstall
    on Sep 11, 2022
  4. dranikpg
    added a commit that references this issue on Sep 12, 2022

    Address #534 - handling missing mime types gracefully (#536)

    0b90bb4
  5. dranikpg
    closed this as completedon Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @jake-arkinstall
    jake-arkinstall

Labels

featureCode based project improvementgood first issuean issue suitable to start contributing to the project

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402792 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.