Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dnl | to obtain it through the world-wide-web, please send a note to |
dnl | license@swoole.com so we can mail you a copy immediately. |
dnl +----------------------------------------------------------------------+
dnl | Author: Tianfeng Han <mikan.tenny@gmail.com> |
dnl | Author: Twosee <twose@qq.com> |
dnl +----------------------------------------------------------------------+

PHP_ARG_ENABLE(debug-log, enable debug log,
Expand Down Expand Up @@ -278,16 +279,21 @@ if test "$PHP_SWOOLE" != "no"; then
AC_CHECK_LIB(pthread, pthread_barrier_init, AC_DEFINE(HAVE_PTHREAD_BARRIER, 1, [have pthread_barrier_init]))
AC_CHECK_LIB(pcre, pcre_compile, AC_DEFINE(HAVE_PCRE, 1, [have pcre]))

AC_CHECK_LIB(brotlienc, BrotliEncoderCreateInstance, [
AC_DEFINE(SW_HAVE_BROTLI, 1, [have brotli])
PHP_ADD_LIBRARY(brotlienc, 1, SWOOLE_SHARED_LIBADD)
])

AC_CHECK_LIB(z, gzgets, [
AC_DEFINE(SW_HAVE_COMPRESSION, 1, [have compression])
AC_DEFINE(SW_HAVE_ZLIB, 1, [have zlib])
PHP_ADD_LIBRARY(z, 1, SWOOLE_SHARED_LIBADD)
])

AC_CHECK_LIB(brotlienc, BrotliEncoderCreateInstance, [
AC_CHECK_LIB(brotlidec, BrotliDecoderCreateInstance, [
AC_DEFINE(SW_HAVE_COMPRESSION, 1, [have compression])
AC_DEFINE(SW_HAVE_BROTLI, 1, [have brotli encoder])
PHP_ADD_LIBRARY(brotlienc, 1, SWOOLE_SHARED_LIBADD)
PHP_ADD_LIBRARY(brotlidec, 1, SWOOLE_SHARED_LIBADD)
])
])

PHP_ADD_LIBRARY(pthread)
PHP_SUBST(SWOOLE_SHARED_LIBADD)

Expand Down
2 changes: 1 addition & 1 deletion include/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ struct _swServer
* parse multipart/form-data files to match $_FILES
*/
uint32_t http_parse_files :1;
#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
/**
* http content compression
*/
Expand Down
2 changes: 2 additions & 0 deletions include/swoole.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ static sw_inline int sw_mem_equal(const void *v1, size_t s1, const void *v2, siz
#define sw_strndup strndup
#endif

#define SW_Z_BEST_SPEED 1

/** always return less than size, zero termination */
size_t sw_snprintf(char *buf, size_t size, const char *format, ...);
size_t sw_vsnprintf(char *buf, size_t size, const char *format, va_list args);
Expand Down
4 changes: 2 additions & 2 deletions src/server/master.cc
Original file line number Diff line number Diff line change
Expand Up @@ -720,10 +720,10 @@ void swServer_init(swServer *serv)
//http server
serv->http_parse_cookie = 1;
serv->http_parse_post = 1;
#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
serv->http_compression = 1;
#endif
serv->http_compression_level = 1; // Z_BEST_SPEED
serv->http_compression_level = SW_Z_BEST_SPEED;
serv->upload_tmp_dir = sw_strdup("/tmp");

serv->buffer_input_size = SW_BUFFER_INPUT_SIZE;
Expand Down
10 changes: 6 additions & 4 deletions swoole_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct http_context
uint32_t completed :1;
uint32_t end :1;
uint32_t send_header :1;
#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
uint32_t enable_compression :1;
uint32_t accept_compression :1;
#endif
Expand All @@ -128,7 +128,7 @@ struct http_context
uint32_t parse_files :1;
uint32_t co_socket :1;

#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
int8_t compression_level;
int8_t compression_method;
#endif
Expand Down Expand Up @@ -205,7 +205,7 @@ extern zend_class_entry *swoole_http_response_ce;

extern swString *swoole_http_buffer;
extern swString *swoole_http_form_data_buffer;
#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
extern swString *swoole_zlib_buffer;
#endif

Expand Down Expand Up @@ -239,11 +239,13 @@ size_t swoole_http_requset_parse(http_context *ctx, const char *data, size_t len
bool swoole_http_response_set_header(http_context *ctx, const char *k, size_t klen, const char *v, size_t vlen, bool ucwords);
void swoole_http_response_end(http_context *ctx, zval *zdata, zval *return_value);

#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
int swoole_http_response_compress(swString *body, int method, int level);
void swoole_http_get_compression_method(http_context *ctx, const char *accept_encoding, size_t length);
const char* swoole_http_get_content_encoding(http_context *ctx);
#endif

#ifdef SW_HAVE_ZLIB
static sw_inline voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size)
{
return (voidpf) safe_emalloc(items, size, 0);
Expand Down
10 changes: 5 additions & 5 deletions swoole_http2_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ static int http2_build_header(http_context *ctx, uchar *buffer, size_t body_leng
}

// content encoding
#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
if (ctx->accept_compression)
{
const char *content_encoding = swoole_http_get_content_encoding(ctx);
Expand All @@ -286,7 +286,7 @@ static int http2_build_header(http_context *ctx, uchar *buffer, size_t body_leng
#endif

// content length
#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
if (ctx->accept_compression)
{
body_length = swoole_zlib_buffer->length;
Expand Down Expand Up @@ -342,7 +342,7 @@ int swoole_http2_server_do_response(http_context *ctx, swString *body)
char header_buffer[SW_BUFFER_SIZE_STD];
int ret;

#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
if (ctx->accept_compression)
{
if (body->length == 0 || swoole_http_response_compress(body, ctx->compression_method, ctx->compression_level) != SW_OK)
Expand Down Expand Up @@ -414,7 +414,7 @@ int swoole_http2_server_do_response(http_context *ctx, swString *body)
size_t l;
size_t send_n;

#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
if (ctx->accept_compression)
{
p = swoole_zlib_buffer->str;
Expand Down Expand Up @@ -605,7 +605,7 @@ static int http2_parse_header(http2_session *client, http_context *ctx, int flag
);
continue;
}
#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
else if (ctx->enable_compression && strncasecmp((char *) nv.name, "accept-encoding", nv.namelen) == 0)
{
swoole_http_get_compression_method(ctx, (char *) nv.value, nv.valuelen);
Expand Down
2 changes: 1 addition & 1 deletion swoole_http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static sw_inline void http_client_append_content_length(swString* buf, int lengt
swString_append_ptr(buf, content_length_str, n);
}

#ifdef SW_HAVE_ZLIB
#ifdef SW_HAVE_COMPRESSION
extern swString *swoole_zlib_buffer;
#endif

Expand Down
Loading