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

XMLHttpRequest (HttpRequest) does not append request headers properly. #4595

Closed
DartBot opened this issue Aug 19, 2012 · 6 comments
Closed
Labels
closed-invalid Closed as we don't believe the reported issue is generally actionable
Milestone

Comments

@DartBot
Copy link

DartBot commented Aug 19, 2012

This issue was originally filed by [email protected]


Dart SDK 10595

Can't append request headers:

Produces: Access-Control-Request-Headers: origin, content-type, accept, x-couchdb-www-authenticate????
void processLogin() {
  String url = "${couchdb}/_session";
  String data = "name=${getUsername()}&password=${getPassword()}";
  
  XMLHttpRequest request = new XMLHttpRequest();
  request.on.loadEnd.add((XMLHttpRequestProgressEvent e) => _onLoadEnd(request));
  request.open("POST", url, async : true);
  request.setRequestHeader("X-CouchDB-WWW-Authenticate", "Cookie");
  request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  request.setRequestHeader("Accept", "application/json");
  request.send(data);
}

Looks like:
OPTIONS /couchdb/_session HTTP/1.1
Host: 127.0.0.1
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://127.0.0.1:3030
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.6 (KHTML, like Gecko) Chrome/23.0.1234.0 (Dart) Safari/537.6
Access-Control-Request-Headers: origin, content-type, accept, x-couchdb-www-authenticate
Accept: /
Referer: http://127.0.0.1:3030/Users/branflake2267/git/dart-examples/examples/DartExamples/DemoCouchDb/DemoCouchDb.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

https://groups.google.com/a/dartlang.org/d/topic/misc/MxQPRyKJxMU/discussion

@sethladd
Copy link
Contributor

I tested this, and Dartium is not setting the header. When I compile this to JavaScript, I see the header.

#import('dart:html');

void main() {
  XMLHttpRequest request = new XMLHttpRequest();
  request.on.load.add((Event function) => print('done!'));
  request.open("GET", "xhrheaders.dart");
  request.setRequestHeader("X-Awesome", "youknowit");
  request.send();
}

Dartium: no X-Awesome

dart2js: yes X-Awesome

See screenshots


Attachments:
[Screen shot 2012-08-20 at 3.07.46 PM.png](https://storage.googleapis.com/google-code-attachments/dart/issue-4595/comment-1/Screen shot 2012-08-20 at 3.07.46 PM.png) (93.87 KB)
[Screen shot 2012-08-20 at 3.08.33 PM.png](https://storage.googleapis.com/google-code-attachments/dart/issue-4595/comment-1/Screen shot 2012-08-20 at 3.08.33 PM.png) (98.06 KB)


Added Area-Dartium, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Aug 21, 2012

This comment was originally written by [email protected]


Do you think this fix will make it into M1?

@sethladd
Copy link
Contributor

Not sure yet, waiting for an engineer to check it out.

@DartBot
Copy link
Author

DartBot commented Aug 22, 2012

This comment was originally written by [email protected]


Pavel, please, may you have a look?


Set owner to [email protected].
Added this to the M1 milestone.

@DartBot
Copy link
Author

DartBot commented Aug 24, 2012

This comment was originally written by [email protected]


Seth, there are two requests for xhrheaders.dart on the screenshot. The first one is resource request from html parser, and the second one is xhr from the script. Only xhr should have X-Awesome header.

As for original issue, it looks like CORS preflight request (note that the method is "OPTIONS", not "POST"). Preflight request should be followed by a POST request that will have all the headers set.


Added Invalid label.

@sethladd
Copy link
Contributor

Thank you for looking into this.

@DartBot DartBot added Type-Defect closed-invalid Closed as we don't believe the reported issue is generally actionable labels Aug 24, 2012
@DartBot DartBot added this to the M1 milestone Aug 24, 2012
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-invalid Closed as we don't believe the reported issue is generally actionable
Projects
None yet
Development

No branches or pull requests

2 participants