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

Empty post body #86

Closed
andig opened this issue Dec 28, 2016 · 1 comment
Closed

Empty post body #86

andig opened this issue Dec 28, 2016 · 1 comment

Comments

@andig
Copy link
Contributor

andig commented Dec 28, 2016

Using https://github.com/reactphp/http/tree/cd15204bd15d106d7832c680e4fb0ca0ce2f5e30 I've noticed that I'm no longer receiving post bodies:

➜  vz git:(next) ✗ curl  -m 3 -X POST -d '{"data":[{"uuid":"a16e7380-ccf7-11e6-aa5c-1195f3e90cce","tuples":[[1,1,1]]}]}' 

This is the code:

function __construct(ReactSocketServer $socket, MiddlewareAdapter $hub) {
	parent::__construct($socket);
	$this->hub = $hub;
	$this->on('request', array($this, 'onRequest'));
}

/**
 * main push request/ websocket response loop
 */
function onRequest(Request $request, Response $response) {
	$content = '';
	$headers = $request->getHeaders();
	$contentLength = isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : null;

	// length required, chunked encoding not supported
	if (null === $contentLength) {
		$response->writeHead(411);
		$response->end();
		return;
	}

	$request->on('data', function($data) use ($request, $response, &$content, $contentLength) {
		// read data (may be empty for GET request)
		$content .= $data;

		// handle request after receive
		if (strlen($content) >= $contentLength) {
	
		}
	});

Imho on('request')->on('data') should still work but the inner on is only called once with empty data (string(0) "").

Any idea why/where this suddenly fails? Definitely working before...

@andig
Copy link
Contributor Author

andig commented Jan 2, 2017

Darn. If you use curl make sure to add -H "Content-Type: application/json" or you won't get a post body.

@andig andig closed this as completed Jan 2, 2017
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