Fix nextcloud issues

This commit is contained in:
2023-07-02 13:50:07 +02:00
parent cd25120362
commit cb04af739c
6 changed files with 22 additions and 7 deletions

View File

@ -108,7 +108,7 @@ static int async_exec(evt_listen_t *evt, async_evt_t r_events) {
int ret, e = errno; int ret, e = errno;
if (r_events & evt->events) { if (r_events & evt->events) {
// specified event(s) occurred // specified event(s) occurred
if (evt->socket && !sock_has_pending(evt->socket)) { if (evt->socket && !sock_has_pending(evt->socket, 0)) {
evt->err_cb(evt->arg); evt->err_cb(evt->arg);
ret = 0; ret = 0;
} else { } else {

View File

@ -460,3 +460,11 @@ int http_get_compression(const http_req *req, const http_res *res) {
} }
return 0; return 0;
} }
long http_get_keep_alive_timeout(http_hdr *hdr) {
const char *keep_alive = http_get_header_field(hdr, "Keep-Alive");
if (!keep_alive) return -1;
const char *timeout = strstr(keep_alive, "timeout=");
if (!timeout) return -1;
return strtol(timeout + 8, NULL, 10);
}

View File

@ -188,4 +188,6 @@ const http_doc_info *http_get_status_info(status_code_t status_code);
int http_get_compression(const http_req *req, const http_res *res); int http_get_compression(const http_req *req, const http_res *res);
long http_get_keep_alive_timeout(http_hdr *hdr);
#endif //SESIMOS_HTTP_H #endif //SESIMOS_HTTP_H

View File

@ -394,8 +394,8 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
while (retry) { while (retry) {
errno = 0; errno = 0;
if (!proxy->initialized || sock_has_pending(&proxy->proxy) != 0 || srv_error || if (!proxy->initialized || sock_has_pending(&proxy->proxy, SOCK_DONTWAIT) != 0 || srv_error ||
(proxy->http_timeout != 0 && (clock_micros() - proxy->proxy.ts_last) > proxy->http_timeout)) (proxy->http_timeout != 0 && (clock_micros() - proxy->proxy.ts_last) >= proxy->http_timeout))
{ {
if (proxy->initialized) if (proxy->initialized)
proxy_close(proxy); proxy_close(proxy);
@ -536,7 +536,8 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
} }
sock_recv_x(&proxy->proxy, buffer, header_len, 0); sock_recv_x(&proxy->proxy, buffer, header_len, 0);
// TODO read timeout from Keep-Alive long keep_alive_timeout = http_get_keep_alive_timeout(&res->hdr);
proxy->http_timeout = (keep_alive_timeout > 0) ? keep_alive_timeout * 1000000 : 0;
ret = proxy_response_header(req, res, conf); ret = proxy_response_header(req, res, conf);
if (ret != 0) { if (ret != 0) {

View File

@ -386,14 +386,16 @@ int sock_close(sock *s) {
return 0; return 0;
} }
int sock_has_pending(sock *s) { int sock_has_pending(sock *s, int flags) {
int e = errno; int e = errno;
long ret; long ret;
if (s->pipe) { if (s->pipe) {
ioctl(s->socket, FIONREAD, &ret); ioctl(s->socket, FIONREAD, &ret);
} else if (s->enc && (flags & SOCK_DONTWAIT)) {
ret = SSL_pending(s->ssl);
} else { } else {
char buf[1]; char buf[1];
ret = sock_recv(s, &buf, sizeof(buf), MSG_PEEK | MSG_DONTWAIT); ret = sock_recv(s, &buf, sizeof(buf), MSG_PEEK | ((flags & SOCK_DONTWAIT) ? MSG_DONTWAIT : 0));
} }
errno = e; errno = e;
return ret > 0; return ret > 0;

View File

@ -19,6 +19,8 @@
#define SOCK_ENCRYPTED 1 #define SOCK_ENCRYPTED 1
#define SOCK_PIPE 2 #define SOCK_PIPE 2
#define SOCK_DONTWAIT 1
typedef struct { typedef struct {
unsigned int enc:1, pipe:1; unsigned int enc:1, pipe:1;
int socket; int socket;
@ -68,7 +70,7 @@ long sock_splice_chunked(sock *dst, sock *src, void *buf, unsigned long buf_len,
int sock_close(sock *s); int sock_close(sock *s);
int sock_has_pending(sock *s); int sock_has_pending(sock *s, int flags);
long sock_recv_chunk_header(sock *s); long sock_recv_chunk_header(sock *s);