Unknown Format exception with text/plain,text/html; Accept header - ruby-on-rails

The accept header "Accept: text/plain,text/html;" works for sites like http://nginx.org. However when I run it locally against my Rails 4.1 app
curl -v -H "Accept: text/plain,text/html;" localhost:3000/
on a html responding homepage, I get a 500 error page for an ActionController::UnknownFormat execption.
When I curl
curl -v -H "Accept: text/plain,text/html" localhost:3000
everything works fine (notice the missing ;)
How can I also make it work for Accept: text/plain,text/html; case?

Apparently it's malformed according to RFC 7231 and shouldn't work. nginx.org turns back 200 OK even for obviously malformed MIME types.
See also https://github.com/rails/rails/issues/21749

Related

Swagger UI generating wrong Curl command

Swagger UI generating wrong Curl command as pasted below and due to this query string truncating
curl -X GET http://domain:8080/v1/endpoint?access_token=affsfafasfa&type=1 -H "accept: application/json" -H "content-type: application/json"
the correct Curl command should be like this
curl -X GET 'http://domain:8080/v1/endpoint?access_token=affsfafasfa&type=1' -H "accept: application/json" -H "content-type: application/json"
the difference between above two command is quote around http url . So please tell me how to achieve this in swagger ui ?
I guess you found a bug in the new version. The very latest code already contains a fix for it.
Its an bug in swagger ui version 3.0.2 and swagger support team has fixed this bug now https://github.com/swagger-api/swagger-ui/issues/2839

Spring Boot and XMLHttpRequest

I am having a hard time understanding how Spring Boot (v1.3.3) handles the X-Requested-With: XMLHttpRequest header. My understanding is that this header tells Spring Boot to return, for requests without an authenticated session, a 401-Unauthorized error rather than a 302-Found with a location to the login page.
I have set up my AngularJS client to send this header for any routing, and then configured an $http interceptor to act on the 401 error by displaying a dialog. Doesn't work for me, with a Spring Boot server with no additional security configuration.
With some investigation with CURL:
It seems that the -H "Accept: application/json" header also needs to be provided.
curl -v -H "X-Requested-With: XMLHttpRequest" localhost:9080/ returns a 302, while curl -v -H "X-Requested-With: XMLHttpRequest" -H "Accept: application/json" localhost:9080/ returns a 401.
Questions: Why is the application/json header required as well? Can I configure it differently (i.e. not require application/json header)? Should I configure it this way, or take another approach? The reason I don't want to require the application/json header is because I am not allowing public access to some resources, such as HTML templates and JS code, and want a 401 returned for these resources as well.
It seems that the JSESSIONID cookie may be affecting the response.
curl -v -H "X-Requested-With: XMLHttpRequest" -H "Accept: application/json" localhost:9080/ returns a 401, while curl -v -H "X-Requested-With: XMLHttpRequest" -H "Accept: application/json" -H "Cookie: JSESSIONID=63EA6E09F64B98938E4495DF9898323A" localhost:9080/' returns a 302.
Questions: Why does the presence of the (valid) JSESSIONID cookie make any difference?
I have looked at the source code for Spring Security and Spring Boot and I just cannot put together the pieces. Any help is much appreciated.

why is this parse.com rest api request failing?

i'm trying to send a parse.com push notification from ruby 1.8.7.
i got a test working with curl. but with ruby's net::http i'm getting Timeout::Error: Resource temporarily unavailable
how can i debug this? i don't know how to see why the parse server is responding differently or otherwise see what's happening. i tried sending the request to my own server and the headers looked ok to me.
i simplified what i'm doing to this:
http = Net::HTTP.new('api.parse.com', 443)
response = http.post("/1/push", "{\"where\":{},\"data\":{\"alert\":\"Elliot net http json test 1\"}}", {"X-Parse-Application-Id"=>"xxxxx", "Content-Type"=>"application/json", "X-Parse-REST-API-Key"=>"xxxxx"})
the json there is hard to read, it's from:
api_req = {:where => {}, :data => {:alert => "Elliot net http json test 1"}}.to_json
puts api_req
# {"where":{},"data":{"alert":"Elliot net http json test 1"}}
i also tried several other ways of sending a request with net::http. same result.
the curl request that worked was:
curl -X POST \
-H "X-Parse-Application-Id: xxxxxx" \
-H "X-Parse-REST-API-Key: xxxxx" \
-H "Content-Type: application/json" \
-d '{
"where": {},
"data": {
"alert": "Elliot curl test #4"
}
}' \
https://api.parse.com/1/push
i'm not using parse-ruby-client because i ran into problems with dependencies assuming a newer version of ruby. all i need to do is send some simple push notifications, and it seems like this should work without too much trouble.
can anyone help me get this working or tell me how to get some useful info about what's happening to debug?
As per the REST API Developers guide,
All API access is over HTTPS, and accessed via the https://api.parse.com domain.
So all you need to do is to add http.use_ssl = true.

How do I make OmniAuth Identity accept JSON post data?

I'm using OmniAuth-Identity for log ins, and logging in using Ajax calls. Attempts to log in passing JSON data don't work.
For instance this works:
curl -i -H "Accept: application/json" -d "auth_key=joe#example.com&password=cheesestix" "http://0.0.0.0:3000/auth/identity/callback"
This doesn't, it returns "invalid credentials"
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{"auth_key":"joe#example.com","password":"cheesestix"}' "http://0.0.0.0:3000/auth/identity/callback"
Is this a known issue? Form encoding my data will be difficult as I'm using AngularJS.
UPDATE:
One of the rails guys fixed it by backporting JSON support into Rack.
gem 'rack', git: 'https://github.com/ssoroka/rack.git', branch: '1.5.2-json-support-backport'
I'm hesitant to post that as an answer becase I don't understand the details of Rack well enough to explain anything. But the relevant diff is here: https://github.com/ssoroka/rack/commit/d8e2e2af6da57805d2f0906ce925ea150def31a0

POST with curl according to a particular format

I'm attempting to gather XML data automatically using curl, and my command so far is
curl -E keyStore.pem -d 'uid=myusername&password=mypassword&active=y&type=F' 'https://www.aidaptest.naimes.faa.gov/aidap/XmlNotamServlet HTTP/1.1/' -k
but it keeps on giving me a "Your browser sent a query this server could not understand." error.
I'm pretty sure that it's connecting since it's not rejecting me, but I don't know how to properly format the POST. Here's some documentation they gave me for the format of the POST request.
POST <URL>/aidap/XmlNotamServlet HTTP/1.1
Content-type: application/x-www-form-urlencoded
Content-length: <input_parameter’s length>
<a blank line>
<input_parameter>`
input_parameter is uid, password, and location_id bit and is correct
Am I doing this correctly from what you can see?
Something like this should do it.
curl -E keyStore.pem -v -X POST -i --header Content-Type:application/x-www-form-urlencoded
-d 'uid=myusername&password=mypassword&active=y&type=F' 'https://www.aidaptest.naimes.faa.gov/aidap/XmlNotamServlet'
I don't think you need HTTP/1.1 at the end of the URL in the command line. And even if you needed it, you certainly don't need the final / character before the closing single quote.

Resources