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

XML#parse not working for response.body_io #4248

Closed
need47 opened this issue Apr 6, 2017 · 5 comments
Closed

XML#parse not working for response.body_io #4248

need47 opened this issue Apr 6, 2017 · 5 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib
Milestone

Comments

@need47
Copy link
Contributor

need47 commented Apr 6, 2017

The XML#parse(io : IO) method seems not working correctly on response.body_io.

require "http/client"
require "xml"

url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi"
form = {
  "db" => "gene",
  "id" => "1956"
}

HTTP::Client.post_form(url, form) do |response|
  if response.status_code == 200
    # xml = XML.parse(response.body_io.gets_to_end) # this is ok
    xml = XML.parse(response.body_io) # not working
    p xml.to_xml
  end
end

Btw, the same example on play gave the following error:

Program received and didn't handle signal SYS (31)

@Sija
Copy link
Contributor

Sija commented Apr 6, 2017

Minimal code to make play fail with above error is:

require "http/client"
require "xml"

url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi"
form = {
  "db" => "gene",
  "id" => "1956"
}

HTTP::Client.post_form(url, form)

https://play.crystal-lang.org/#/r/1toc

@asterite
Copy link
Member

asterite commented Apr 6, 2017

@need47 When you say "seems not working correctly", what do you mean? I ran the snippet and it worked fine (outside of the playground)

@need47
Copy link
Contributor Author

need47 commented Apr 6, 2017

@asterite the snippet compiled and ran fine, while the output is not right. I'm expecting this: https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=gene&id=1956

Basically I'm getting an empty xml now:

<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8" ?>

@asterite
Copy link
Member

asterite commented Apr 6, 2017

Hmm... for some reason xml doesn't like to be fed small chunks of bytes. This happens because the current ssl socket is not buffered. If I change it to buffer it starts working well. I guess that's a solution though I don't know why libxml works wrong otherwise.

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib labels Apr 6, 2017
@asterite asterite added this to the Next milestone Apr 6, 2017
@need47
Copy link
Contributor Author

need47 commented Apr 6, 2017

@asterite thanks for the quick fix.

Should I create a new issue for the "playground"?

Program received and didn't handle signal SYS (31)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib
Projects
None yet
Development

No branches or pull requests

3 participants