Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Content-Type" validation #62

Merged
merged 1 commit into from
Feb 13, 2015
Merged

Fix "Content-Type" validation #62

merged 1 commit into from
Feb 13, 2015

Conversation

dlwr
Copy link

@dlwr dlwr commented Feb 13, 2015

Hello, I found the issue about "Content-Type" validation and fix it.

Here is sample. I wrote JSON Schema like this,

{
  "title": "Material",
  "definitions": {
    "someDefinitions": "someDefinitions"
  },
  "description": "Material",
  "links" : [
    {
      "description" : "Create Material",
      "href" : "/api/v1/materials",
      "method" : "POST",
      "rel" : "self",
      "encType" : "multipart/*"
    }
  ],
  "properties": {
    "someProperties": "someProperties"
  }
}

then, made request like this,

POST /api/v1/materials HTTP/1.1
Host: localhost:3000
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="texture"; filename="sample_texture.jpg"
Content-Type: image/jpeg


----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="title"

sample_title
----WebKitFormBoundary7MA4YWxkTrZu0gW

then, I received error message like this

{
  "error": {
    "status": 400,
    "message": "\"Content-Type\" request header must be set to \"multipart/*\"."
  }
}

This problem was caused by arguments order, they are used by Committee::RequestValidator for call Rack::Mime.match? .

@@ -19,7 +19,7 @@ def call(request, data)

def check_content_type!(request, data)
if request.content_type && !empty_request?(request)
unless Rack::Mime.match?(@link.enc_type, request.content_type)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arguments used conversely here.

this is definition of Rack::Mime.match?
https://github.com/rack/rack/blob/7c574e2593922005ee7993c6aca93aa0383cd973/lib/rack/mime.rb#L28

first argument is expected to value, second is expected to matcher

@brandur
Copy link
Member

brandur commented Feb 13, 2015

Hah, that's embarassing. Thank-you @dlwr!

brandur pushed a commit that referenced this pull request Feb 13, 2015
@brandur brandur merged commit e6616a3 into interagent:master Feb 13, 2015
@brandur
Copy link
Member

brandur commented Feb 13, 2015

Fix pushed in version 1.6.3.

@dlwr dlwr deleted the fix-content-type-validation branch February 16, 2015 02:20
@dlwr
Copy link
Author

dlwr commented Feb 16, 2015

THX!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants