Compare commits
3 Commits
55f2318b57
...
495a3a6aaf
Author | SHA1 | Date | |
---|---|---|---|
495a3a6aaf
|
|||
69dfc562af
|
|||
a2383825ed
|
@@ -573,7 +573,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
|
||||
int chunked = transfer_encoding != NULL && strcmp(transfer_encoding, "chunked") == 0;
|
||||
|
||||
int flags = (chunked ? FASTCGI_CHUNKED : 0) | (use_fastcgi & FASTCGI_COMPRESS);
|
||||
fastcgi_send(&fcgi_conn, client, flags);
|
||||
ret = fastcgi_send(&fcgi_conn, client, flags);
|
||||
} else if (use_rev_proxy) {
|
||||
char *transfer_encoding = http_get_header_field(&res.hdr, "Transfer-Encoding");
|
||||
int chunked = transfer_encoding != NULL && strstr(transfer_encoding, "chunked") != NULL;
|
||||
@@ -585,7 +585,11 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
|
||||
}
|
||||
|
||||
int flags = (chunked ? REV_PROXY_CHUNKED : 0) | (use_rev_proxy & REV_PROXY_COMPRESS);
|
||||
rev_proxy_send(client, len_to_send, flags);
|
||||
ret = rev_proxy_send(client, len_to_send, flags);
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
client_keep_alive = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -61,6 +61,7 @@ int fastcgi_init(fastcgi_conn *conn, int mode, unsigned int client_num, unsigned
|
||||
conn->req_id = req_id;
|
||||
conn->out_buf = NULL;
|
||||
conn->out_off = 0;
|
||||
conn->webroot = uri->webroot;
|
||||
|
||||
int fcgi_sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fcgi_sock < 0) {
|
||||
@@ -215,7 +216,7 @@ int fastcgi_close_stdin(fastcgi_conn *conn) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fastcgi_php_error(const char *msg, int msg_len, char *err_msg) {
|
||||
int fastcgi_php_error(const fastcgi_conn *conn, const char *msg, int msg_len, char *err_msg) {
|
||||
char *msg_str = malloc(msg_len + 1);
|
||||
char *ptr0 = msg_str;
|
||||
strncpy(msg_str, msg, msg_len);
|
||||
@@ -262,7 +263,7 @@ int fastcgi_php_error(const char *msg, int msg_len, char *err_msg) {
|
||||
}
|
||||
print("%s%.*s%s", msg_type == 1 ? WRN_STR : msg_type == 2 ? ERR_STR : "", len2, ptr2, CLR_STR);
|
||||
if (msg_type == 2 && ptr2 == ptr0) {
|
||||
sprintf(err_msg, "%.*s", len2, ptr2);
|
||||
strcpy_rem_webroot(err_msg, ptr2, len2, conn->webroot);
|
||||
err = 1;
|
||||
}
|
||||
if (ptr3 == NULL) {
|
||||
@@ -331,7 +332,7 @@ int fastcgi_header(fastcgi_conn *conn, http_res *res, char *err_msg) {
|
||||
print(ERR_STR "FastCGI protocol error: %i" CLR_STR, body->protocolStatus);
|
||||
}
|
||||
if (app_status != 0) {
|
||||
print(ERR_STR "Script terminated with exit code %i" CLR_STR, app_status);
|
||||
print(ERR_STR "FastCGI app terminated with exit code %i" CLR_STR, app_status);
|
||||
}
|
||||
close(conn->socket);
|
||||
conn->socket = 0;
|
||||
@@ -340,7 +341,7 @@ int fastcgi_header(fastcgi_conn *conn, http_res *res, char *err_msg) {
|
||||
} else if (header.type == FCGI_STDERR) {
|
||||
// TODO implement Necronda backend error handling
|
||||
if (conn->mode == FASTCGI_PHP) {
|
||||
err = err || fastcgi_php_error(content, content_len, err_msg);
|
||||
err = err || fastcgi_php_error(conn, content, content_len, err_msg);
|
||||
}
|
||||
} else if (header.type == FCGI_STDOUT) {
|
||||
break;
|
||||
@@ -457,7 +458,7 @@ int fastcgi_send(fastcgi_conn *conn, sock *client, int flags) {
|
||||
print(ERR_STR "FastCGI protocol error: %i" CLR_STR, body->protocolStatus);
|
||||
}
|
||||
if (app_status != 0) {
|
||||
print(ERR_STR "Script terminated with exit code %i" CLR_STR, app_status);
|
||||
print(ERR_STR "FastCGI app terminated with exit code %i" CLR_STR, app_status);
|
||||
}
|
||||
close(conn->socket);
|
||||
conn->socket = 0;
|
||||
@@ -479,7 +480,7 @@ int fastcgi_send(fastcgi_conn *conn, sock *client, int flags) {
|
||||
} else if (header.type == FCGI_STDERR) {
|
||||
// TODO implement Necronda backend error handling
|
||||
if (conn->mode == FASTCGI_PHP) {
|
||||
fastcgi_php_error(content, content_len, buf0);
|
||||
fastcgi_php_error(conn, content, content_len, buf0);
|
||||
}
|
||||
} else if (header.type == FCGI_STDOUT) {
|
||||
unsigned long avail_in, avail_out;
|
||||
|
@@ -31,6 +31,7 @@ typedef struct {
|
||||
int socket;
|
||||
unsigned short req_id;
|
||||
char *out_buf;
|
||||
const char *webroot;
|
||||
unsigned short out_len;
|
||||
unsigned short out_off;
|
||||
} fastcgi_conn;
|
||||
@@ -42,7 +43,7 @@ int fastcgi_init(fastcgi_conn *conn, int mode, unsigned int client_num, unsigned
|
||||
|
||||
int fastcgi_close_stdin(fastcgi_conn *conn);
|
||||
|
||||
int fastcgi_php_error(const char *msg, int msg_len, char *err_msg);
|
||||
int fastcgi_php_error(const fastcgi_conn *conn, const char *msg, int msg_len, char *err_msg);
|
||||
|
||||
int fastcgi_header(fastcgi_conn *conn, http_res *res, char *err_msg);
|
||||
|
||||
|
@@ -131,3 +131,13 @@ int mime_is_compressible(const char *type) {
|
||||
strcmp(type_parsed, "image/vnd.microsoft.icon") == 0 ||
|
||||
strcmp(type_parsed, "image/x-icon") == 0;
|
||||
}
|
||||
|
||||
int strcpy_rem_webroot(char *dst, const char *src, long len, const char *webroot) {
|
||||
strncpy(dst, src, len);
|
||||
if (webroot == NULL) return 0;
|
||||
char *pos;
|
||||
while ((pos = strstr(dst, webroot)) != NULL) {
|
||||
strcpy(pos, pos + strlen(webroot));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@@ -40,4 +40,6 @@ int url_decode(const char *str, char *dec, long *size);
|
||||
|
||||
int mime_is_compressible(const char *type);
|
||||
|
||||
int strcpy_rem_webroot(char *dst, const char *str, long len, const char *webroot);
|
||||
|
||||
#endif //NECRONDA_SERVER_UTILS_H
|
||||
|
Reference in New Issue
Block a user