I’m having a similar problem to this:
I have a discourse installation running on forum.mydomain.com. I set up a webhook to register user events and have verified it works using RequestBin. However, my receive action only receives headers, but no body. I have disabled csrfvalidation and there is no https redirect.
I also have a mailchimp webhook, and I’m handling that post request nearly identically, and it works just fine. That makes me think it has something to do with the request coming from a subdomain.
public function beforeAction($action)
{
if (in_array($action->id, ['forum-receive'])) {
$this->enableCsrfValidation = false;
}
return parent::beforeAction($action);
}
public function actionForumReceive()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$headers = $request->headers;
if ($headers->has('X-Discourse-Event')
&& $event = $headers->get('X-Discourse-Event')) {
if ($event === 'user_created') {
file_put_contents('discourse.txt', print_r($request, true), FILE_APPEND);
return ['type' => 'new user'];
}
}
throw new NotFoundHttpException;
}
The action returns a response with status 200 and “new user”, but the body is empty. The apache log shows the request was received, but nothing noteworthy. I’m at a loss of what else to look at.
Here is discourse.txt. I’m not sure why, but it says csrfvalidation is still enabled.
yii\web\Request Object
(
[enableCsrfValidation] => 1
[csrfParam] => _csrf-frontend
[csrfCookie] => Array
(
[httpOnly] => 1
)
[enableCsrfCookie] => 1
[enableCookieValidation] => 1
[cookieValidationKey] => zZjHj-Bo1L48qe3Z-yXF437Ym77KTe78l
[methodParam] => _method
[parsers] => Array
(
)
[trustedHosts] => Array
(
)
[secureHeaders] => Array
(
[0] => X-Forwarded-For
[1] => X-Forwarded-Host
[2] => X-Forwarded-Proto
[3] => Front-End-Https
[4] => X-Rewrite-Url
)
[ipHeaders] => Array
(
[0] => X-Forwarded-For
)
[secureProtocolHeaders] => Array
(
[X-Forwarded-Proto] => Array
(
[0] => https
)
[Front-End-Https] => Array
(
[0] => on
)
)
[_cookies:yii\web\Request:private] =>
[_headers:yii\web\Request:private] => yii\web\HeaderCollection Object
(
[_headers:yii\web\HeaderCollection:private] => Array
(
[x-discourse-event] => Array
(
[0] => user_created
)
[x-discourse-event-type] => Array
(
[0] => user
)
[x-discourse-event-id] => Array
(
[0] => 19
)
[x-discourse-instance] => Array
(
[0] => https://forum.mydomain.com
)
[content-type] => Array
(
[0] => application/json
)
[accept] => Array
(
[0] => */*
)
[user-agent] => Array
(
[0] => Discourse/2.4.0.beta10
)
[content-length] => Array
(
[0] => 3936
)
[connection] => Array
(
[0] => close
)
[x-accel-internal] => Array
(
[0] => /internal-nginx-static-location
)
[x-real-ip] => Array
(
[0] => 172.17.0.2
)
[host] => Array
(
[0] => mydomain.com
)
)
)
[_rawBody:yii\web\Request:private] =>
[_bodyParams:yii\web\Request:private] =>
[_queryParams:yii\web\Request:private] =>
[_hostInfo:yii\web\Request:private] =>
[_hostName:yii\web\Request:private] =>
[_baseUrl:yii\web\Request:private] =>
[_scriptUrl:yii\web\Request:private] => /index.php
[_scriptFile:yii\web\Request:private] =>
[_pathInfo:yii\web\Request:private] => forum-receive
[_url:yii\web\Request:private] => /forum-receive
[_port:yii\web\Request:private] =>
[_securePort:yii\web\Request:private] =>
[_contentTypes:yii\web\Request:private] =>
[_languages:yii\web\Request:private] =>
[_csrfToken:yii\web\Request:private] =>
[_isConsoleRequest:yii\base\Request:private] =>
[_events:yii\base\Component:private] => Array
(
)
[_eventWildcards:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] =>
[_scriptFile:yii\base\Request:private] =>
)