Skip to content

Bug with OPTIONS method and Grape 0.18.0 ? #1519

Closed
@thiagohdeplima

Description

@thiagohdeplima

I start a new project today.

This project have the following routes:

get do
  passengers = Passenger.order(:name)

  query = declared(params, include_missing: false)

  unless query.count.zero? then
    passengers = passengers.where(query)
  end

  present passengers.offset(@start).limit(@count).all,
    with: API::V1::Entities::Passenger
end

params do
  requires :name, type: String
  requires :email, type: String
  requires :mobile, type: String
  requires :password, type: String
end
post do
  present Passenger.create(declared(params)),
    with: API::V1::Entities::Passenger
end

Occurs which in grape 0.18.0, when the app receive an request with OPTIONS method, the response is the following:

$ curl -X OPTIONS localhost:9292/v1/passengers -v
*   Trying ::1...
* connect to ::1 port 9292 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9292 (#0)
> OPTIONS /v1/passengers HTTP/1.1
> Host: localhost:9292
> User-Agent: curl/7.49.1
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Content-Length: 85
<
* Connection #0 to host localhost left intact
{"error":"name is missing, email is missing, mobile is missing, password is missing"}

In other project, I use version 0.14.0. Downgrading this project from 0.18.0 to same version, without any other change, the OPTIONS method start working, as bellow:

$ curl -X OPTIONS localhost:9292/v1/passengers -v
*   Trying ::1...
* connect to ::1 port 9292 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9292 (#0)
> OPTIONS /v1/passengers HTTP/1.1
> Host: localhost:9292
> User-Agent: curl/7.49.1
> Accept: */*
>
< HTTP/1.1 204 No Content
< Allow: OPTIONS, GET, POST, HEAD
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Accept
<
* Connection #0 to host localhost left intact

I test with others grape versions (0.15.0 and 0.17.0), and I could not reproduce this bug, it occours only in 0.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions