r0man / cljs-http

A ClojureScript HTTP library.
582 stars 93 forks source link

A request that should return an HTTP 405 instead returns status 0 #112

Closed jmlsf closed 6 years ago

jmlsf commented 6 years ago

If I run this simple code:

(defn testcall [] (go (prn (<! (http/post "http://www.google.com")))))

I get this response:

{:status 0,
 :success false,
 :body "",
 :headers {},
 :trace-redirects ["http://www.google.com" "http://www.google.com"],
 :error-code :http-error,
 :error-text " [0]"}

This result seems incorrect in several respects:

  1. We should be getting an HTTP 405.
  2. Even if there were some kind of network error, the GCL documentation states that we should be getting a :status -1, not a :status 0.
  3. What's up with that :error-text " [0]"? That looks like some kind of interop error.
leourbina commented 6 years ago

@jmlsf An HTTP status of 0 means that the request failed and received 0 bytes as a response. If you look at your console you'll probably find something like this

developer_tools_-_http___localhost_8080_

In this case the request failed because Google does not have CORS headers on google.com (probably a good thing). So even though you can POST to it from curl and other similar clients, doing so from the browser will fail for security reasons. Hopefully that helps.

jmlsf commented 6 years ago

What about the :error-text? Is that normal?

leourbina commented 6 years ago

Yep. Just look at your network tab and you'll see that the request was rejected. You're not getting anything back from the server. Consider closing this ticket as this is not a bug.