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

cljs-http.core/xhr does not set header content type and correct request method name #76

Closed
Mamun opened this issue Sep 3, 2015 · 1 comment

Comments

@Mamun
Copy link

Mamun commented Sep 3, 2015

  • What will be request method for example in bellow?
  • What will be header content-type for example in bellow?

(http/post "http://example.com" {:edn-params {:foo :bar}})

When headers set "content-type" with "application/x-www-form-urlencoded", it is setting correct content type with request method POST. But with other type, content type is not set and request method is OPTIONS.

  • Working example

(go
(let [r {:with-credentials? false,
:scheme :http,
:server-name "localhost",
:server-port 3000,
:uri "/post",
:headers {"content-type" "application/x-www-form-urlencoded"},
:request-method :post
:query-params nil,
:query-string nil,
:body "a=1",
}](->
%28xhr r%29
%28<!%29
%28log%29)))

Here
General
Remote Address:127.0.0.1:3000
Request URL:http://localhost:3000/post
Request Method:POST
Status Code:200 OK

Request Headers
Accept:/
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:3
Content-Type:application/x-www-form-urlencoded
Host:localhost:3000
Origin:http://localhost:3449
Referer:http://localhost:3449/

  • Error example

(go
(let [r {:with-credentials? false,
:scheme :http,
:server-name "localhost",
:server-port 3000,
:uri "/post",
:headers {"content-type" "application/edn"},
:request-method :post
:query-string nil,
:query-params nil,
:body (pr-str {:a 1}),
}](->
%28xhr r%29
%28<!%29
%28log%29)))

General
Remote Address:127.0.0.1:3000
Request URL:http://localhost:3000/post
Request Method:OPTIONS
Status Code:200 OK

Request headers
Accept:/
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:localhost:3000
Origin:http://localhost:3449
Referer:http://localhost:3449/

This is not an issue for cljs-http but goog.net.xhr.

@Mamun
Copy link
Author

Mamun commented Sep 3, 2015

This is the case for cross domain. But in same domain, it sets correctly. Not an issue.

@Mamun Mamun closed this as completed Sep 3, 2015
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

No branches or pull requests

1 participant