From: Peter Cowburn Date: Tue, 10 Mar 2015 13:22:16 +0000 (+0000) Subject: Handle application/json as well X-Git-Tag: v1.0.0RC2~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=27c5605043a78052ef303a573c5b93858ec4d0f4;p=m6w6%2Fext-json_post Handle application/json as well --- diff --git a/php_json_post.c b/php_json_post.c index cb8a53b..fd3165c 100644 --- a/php_json_post.c +++ b/php_json_post.c @@ -130,14 +130,13 @@ static SAPI_POST_HANDLER_FUNC(php_json_post_handler) PHP_MINIT_FUNCTION(json_post) { - sapi_post_entry entry = {NULL, 0, NULL, NULL}; + sapi_post_entry json_post_entries[] = { + { "text/json", sizeof("text/json")-1, sapi_read_standard_form_data, php_json_post_handler }, + { "application/json", sizeof("application/json")-1, sapi_read_standard_form_data, php_json_post_handler }, + { NULL, 0, NULL, NULL } + }; - entry.post_reader = sapi_read_standard_form_data; - entry.post_handler = php_json_post_handler; - - entry.content_type = "text/json"; - entry.content_type_len = sizeof("text/json")-1; - sapi_register_post_entry(&entry TSRMLS_CC); + sapi_register_post_entries(json_post_entries TSRMLS_CC); ZEND_INIT_MODULE_GLOBALS(json_post, php_json_post_init_globals, NULL); REGISTER_INI_ENTRIES(); diff --git a/tests/application.phpt b/tests/application.phpt new file mode 100644 index 0000000..1331be4 --- /dev/null +++ b/tests/application.phpt @@ -0,0 +1,24 @@ +--TEST-- +json_post with Content-Type: application/json +--SKIPIF-- + +--POST_RAW-- +Content-Type: application/json + +{ + "greeting": "Hello World" +} +--FILE-- + +Done +--EXPECTF-- +array(1) { + ["greeting"]=> + string(11) "Hello World" +} +int(0) +Done