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

Droopy hangs on multipart/forms uploads with happyhttp library #16

Open
stmueller opened this issue Jun 2, 2017 · 0 comments
Open

Droopy hangs on multipart/forms uploads with happyhttp library #16

stmueller opened this issue Jun 2, 2017 · 0 comments

Comments

@stmueller
Copy link

I am attempting to use happy to implement a POST command using multipart/formdata using happyhttp (e.g., https://github.com/Zintinio/HappyHTTP) to upload files to droopy directly from a c++ application.
The issue is that the server will accept the POST command and create the file as requested, but it when trying to get the return page data. This is likely an interaction between some low-level implementation in droopy and in happyhttp, but a suitably-modified test case works for other servers, such as http://posttestserver.com/upload.php. Furthermore, the test code I have will work when pointed to a straight html page--it successfully downloads the page data.

The underlying situation is that happy tries to download the data, and although it knows there is outstanding data to process, it checks whether there is data waiting on the open socket and finds there is none. I don't really know what that means on the droopy side, but when I ctrl-c out of the program, droopy throws this error--this may not really be meaningful.

127.0.0.1 - - [02/Jun/2017 08:57:52] "POST / HTTP/1.1" 200 -
127.0.0.1 - - [02/Jun/2017 08:57:52] [Errno 32] Broken pipe
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 50762)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 596, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 654, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 713, in finish
    self.wfile.close()
  File "/usr/lib/python2.7/socket.py", line 283, in close
    self.flush()
  File "/usr/lib/python2.7/socket.py", line 307, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------

A happyhttp test case can be put into Test.cpp is as follows. Just add this after Test3.cpp, which can be compiled via g++ test.cpp happyhttp.cpp -o testpost

then, test with droopy running on localhost:8000

//This posts to local droopy server running on 8000
void Test4()
{
	puts("-----------------Test4------------------------" );
	// POST example using lower-level interface

	const char* params = "--||||\nContent-Disposition: form-data; name=\"upfile\"; filename=\"testfile.txt\" \nContent-Type: application/octet-stream \n\nfile contents1\nfile contents2\nfile contents3\nfile contents4\nfile contents5\nfile contents6\nfile contents7\nfile contents8\nfile contents9\nfile contents10\n--||||--";
	int l = strlen(params);

	happyhttp::Connection conn( "localhost", 8000 );
	conn.setcallbacks( OnBegin, OnData, OnComplete, 0 );

	conn.putrequest( "POST", "/" );
	conn.putheader( "Connection", "close" );
	conn.putheader( "Content-Length", l );
	conn.putheader( "Content-Type", "multipart/form-data; boundary=||||" );
	conn.putheader( "Accept", "text/plain" );
	conn.endheaders();
	conn.send( (const unsigned char*)params, l );

	while( conn.outstanding() )
	  {
		conn.pump();
	  }
}

and later:

try
	{
	  //Test1();
	  //Test2();
	  //Test3();
	  Test4();
	}

The problem seems to be that outstanding() returns true, but when pump() is called, it returns on the datawaiting check:

	if( !datawaiting( m_Sock ) )
		return;				// recv will block

I can't be sure whether happy or droopy are to blame; this works when pointed to posttestserver.com/upload.php, retrieving the custom response code; but fails on droopy. On the other hand, droopy works fine when used via a browser.

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