X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_functions.c;h=e731d9af041343c08112d467568f228d7d7a9f75;hp=9156ccc393187ce2a6fa5912059f75133efc6b83;hb=930417f55598b5b4c54b44e20935450210454fdf;hpb=5de7bf562f55eae49d3424670ad56f68458ad7f1 diff --git a/http_functions.c b/http_functions.c index 9156ccc..e731d9a 100644 --- a/http_functions.c +++ b/http_functions.c @@ -251,6 +251,44 @@ PHP_FUNCTION(http_negotiate_charset) } /* }}} */ +/* {{{ proto string http_negotiate_ctype(array supported[, array &result]) + * + * This function negotiates the clients preferred content type based on its + * Accept HTTP header. The qualifier is recognized and content types + * without qualifier are rated highest. + * + * Expects an array as parameter cotaining the supported content types as values. + * If the optional second parameter is supplied, it will be filled with an + * array containing the negotiation results. + * + * Returns the negotiated content type or the default content type + * (i.e. first array entry) if none match. + * + * Example: + *
+ * 
+ * 
+ */ +PHP_FUNCTION(http_negotiate_content_type) +{ + zval *supported, *rs_array = NULL; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|z", &supported, &rs_array)) { + RETURN_FALSE; + } + + if (rs_array) { + zval_dtor(rs_array); + array_init(rs_array); + } + + HTTP_DO_NEGOTIATE(content_type, supported, rs_array); +} +/* }}} */ + /* {{{ proto bool http_send_status(int status) * * Send HTTP status code.