lapis icon indicating copy to clipboard operation
lapis copied to clipboard

"Content-Type" check

Open subnetmarco opened this issue 10 years ago • 3 comments

Is there a way to tell that an endpoint can only be invoked with a specific Content-Type, and if the Content-Type doesn't match it returns a 415 Unsupported Media Type response ?

subnetmarco avatar Mar 17 '15 21:03 subnetmarco

There is no built in helper for doing that, but it should be fairly easy to write your own. @req.headers holds the request headers. I can write an example if you want.

leafo avatar Mar 17 '15 23:03 leafo

I've implemented the functionality by manually checking req.headers.

As a feature request, it would be nice if the framework could handle that in a helper to make it possible to implement endpoints that accept specific content types.

subnetmarco avatar Mar 17 '15 23:03 subnetmarco

@thefosk What would you like such a thing to look like? Something like:

class extends lapis.Application
  [upload: "/upload"]: respond_to {
    POST: content_type {
      ["image/jpeg"]: =>
        do_something!

? (Note: I have no idea if that syntax could even work..just guessing based on my usage of json_params and respond_to. :sweat_smile:)

TangentFoxy avatar Aug 03 '16 08:08 TangentFoxy