コード例 #1
0
ファイル: http_cache_api.c プロジェクト: ngourdeau/pecl-http
/* {{{ STATUS http_cache_last_modified(time_t, time_t, char *, size_t) */
PHP_HTTP_API STATUS _http_cache_last_modified(time_t last_modified,
	time_t send_modified, const char *cache_control, size_t cc_len TSRMLS_DC)
{
	char *sent_header = NULL;
	
	if (SG(headers_sent)) {
		return FAILURE;
	}
	
	if (cc_len && (SUCCESS != http_send_cache_control(cache_control, cc_len))) {
		return FAILURE;
	}

	if (SUCCESS != http_send_last_modified_ex(send_modified, &sent_header)) {
		return FAILURE;
	}

	if (http_match_last_modified("HTTP_IF_MODIFIED_SINCE", last_modified)) {
		http_exit_ex(304, sent_header, NULL, 0);
	} else {
		STR_FREE(sent_header);
	}

	return SUCCESS;
}
コード例 #2
0
ファイル: http_cache_api.c プロジェクト: ARYANJASHWAL/php7
/* {{{ STATUS http_cache_etag(char *, size_t, char *, size_t) */
PHP_HTTP_API STATUS _http_cache_etag(const char *etag, size_t etag_len,
	const char *cache_control, size_t cc_len TSRMLS_DC)
{
	char *sent_header = NULL;
	
	if (SG(headers_sent)) {
		return FAILURE;
	}
	
	if (cc_len && (SUCCESS != http_send_cache_control(cache_control, cc_len))) {
		return FAILURE;
	}

	if (etag_len) {
		if (SUCCESS != http_send_etag_ex(etag, etag_len, &sent_header)) {
			return FAILURE;
		}
		if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) {
			http_exit_ex(304, sent_header, NULL, 0);
		} else {
			STR_FREE(sent_header);
		}
		return SUCCESS;
	}
	
	/* start ob_etaghandler */
	return http_start_ob_etaghandler();
}
コード例 #3
0
ファイル: http_cache_api.c プロジェクト: ngourdeau/pecl-http
/* {{{ void http_ob_etaghandler(char *, uint, char **, uint *, int) */
void _http_ob_etaghandler(char *output, uint output_len,
	char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
{
	/* passthru */
	*handled_output_len = output_len;
	*handled_output = estrndup(output, output_len);
	
	/* are we supposed to run? */
	if (HTTP_G->etag.started) {
		/* initialize the etag context */
		if (mode & PHP_OUTPUT_HANDLER_START) {
			HTTP_G->etag.ctx = http_etag_init();
		}
		
		/* update */
		http_etag_update(HTTP_G->etag.ctx, output, output_len);
		
		/* finish */
		if (mode & PHP_OUTPUT_HANDLER_END) {
			char *sent_header = NULL;
			char *etag = http_etag_finish(HTTP_G->etag.ctx);
			
			HTTP_G->etag.ctx = NULL;
			
			http_send_cache_control(HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL));
			http_send_etag_ex(etag, strlen(etag), &sent_header);
			
			if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) {
				/* force exit; ob within ob does not work */
				HTTP_G->force_exit = 1;
				http_exit_ex(304, sent_header, etag, 0);
			}
			
			STR_FREE(sent_header);
			STR_FREE(etag);
		}
	}
}