Skip to content

Commit 131ea7f

Browse files
committed
fix webhook error on apache server
1 parent 41d0ad8 commit 131ea7f

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

lib/request.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,28 @@ protected function headers() {
108108
return $this->headers;
109109
}
110110

111-
if ( function_exists( 'getallheaders' ) ) {
112-
113-
$this->headers = getallheaders();
114-
return $this->headers;
115-
}
116-
/**
117-
* Nginx and pre 5.4 workaround.
118-
* @see http://www.php.net/manual/en/function.getallheaders.php
119-
*/
120111
$this->headers = array();
121-
foreach ( $_SERVER as $name => $value ) {
122-
if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
123-
$this->headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
112+
if ( function_exists( 'getallheaders' ) ) {
113+
$headers = getallheaders();
114+
// github webhook
115+
// content-type: application/json
116+
// Expect:
117+
// User-Agent: GitHub-Hookshot/7a71d82
118+
// X-GitHub-Delivery: a331b200-2537-11e8-9d7e-ce0853020b44
119+
// X-GitHub-Event: push
120+
// X-Hub-Signature: sha1=98185ffa2c4684c9a1324c57086709acca9dddc7
121+
foreach ( $headers as $name => $value ) {
122+
$this->headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', $name ) ) ) ) ] = $value;
123+
}
124+
} else {
125+
/**
126+
* Nginx and pre 5.4 workaround.
127+
* @see http://www.php.net/manual/en/function.getallheaders.php
128+
*/
129+
foreach ( $_SERVER as $name => $value ) {
130+
if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
131+
$this->headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
132+
}
124133
}
125134
}
126135

0 commit comments

Comments
 (0)