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

POST request times out in Win32 when posting a file with CR,LF line terminator. #89

Open
quicoju opened this issue Jun 18, 2015 · 6 comments

Comments

@quicoju
Copy link

quicoju commented Jun 18, 2015

In Windows, when doing a POST request a file with CR,LF newlines, the request times out. I tried to trace down the problem and what I have found so far is that when the Content-Length is calculated, the file size is calculated correctly. On the other hand, the number of bytes received by the server equals the Content-Length minus the number of lines in the file, that's why the server times out waiting for the total of bytes to be transferred.

I'm not expert in how the PerlIO layers work, but the documentation mentions that in MS-DOS like systems a translation from CR,LF into \n is made, so that's seems to be the reason why the server is reading one byte short per each line of the file. If I change the file handle to binmode before my request, the problem is fixed.

This is where the questions arise: Is it responsability of the user to set the file handle to binmode? Or should this be transparent to the user?

I noticed the problem when the test t\100_low\09_body.t failed because the file was transformed to CRLF terminators when I cloned from github. If the file has the Unix terminator, the test is successful.

Thanks

@quicoju quicoju changed the title POST request times in Win32 out when posting a file with CR,LF line terminator. POST request times out in Win32 when posting a file with CR,LF line terminator. Jun 18, 2015
@mattn
Copy link
Contributor

mattn commented Jun 19, 2015

could you please show me a minimal script which can reproduce?

@quicoju
Copy link
Author

quicoju commented Jun 19, 2015

Sure, this is basically the second test-tcp from the 09_body.t test file. You can change the open line so it opens a file with CR,LF terminators. Link to gist.

@quicoju
Copy link
Author

quicoju commented Jun 25, 2015

Hello! Would like to add that I can take some of my time to help with this. Sorry for writing this within the issue thread, but I don't know if there are other means of communication (mailing list, irc, etc) for the project. Thanks!

@mattn
Copy link
Contributor

mattn commented Jun 26, 2015

sorry about delay. I'm looking this just now. when using '<:raw' works fine but not for '<'. it seems client code works fine for me..

@mattn
Copy link
Contributor

mattn commented Jun 26, 2015

You need to set :raw layer for open.

open my $req_content_fh, '<:raw', $ARGV[0] or die "oops";  # Any input file with CR,LF line terminators

Because $req_content doesn't contains CR.

@quicoju
Copy link
Author

quicoju commented Jun 26, 2015

Got it man, thanks! So if it's the user's responsibility to set the ':raw' layer when opening the file that is to be posted, then I guess this is something that needs to be documented somewhere in the module's documentation, and maybe the test 09_body.t updated to reflect this as well.If you agree with this, maybe I could take some time to send this in a PR.

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

2 participants