REQ_HEAD,
REQ_POST,
REQ_PUT,
+ REQ_DELETE,
__REQ_MAX
};
[REQ_HEAD] = "HEAD",
[REQ_POST] = "POST",
[REQ_PUT] = "PUT",
+ [REQ_DELETE] = "DELETE",
};
struct uclient_http {
struct ustream_ssl ussl;
struct uloop_timeout disconnect_t;
+ unsigned int seq;
bool ssl_require_validation;
bool ssl;
if (uh->uc.url->port)
port = uh->uc.url->port;
- fd = usock(USOCK_TCP | USOCK_NONBLOCK, uh->uc.url->host, port);
+ memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr));
+
+ fd = usock_inet(USOCK_TCP | USOCK_NONBLOCK, uh->uc.url->host, port, &uh->uc.remote_addr);
if (fd < 0)
return -1;
ustream_fd_init(&uh->ufd, fd);
- memset(&uh->uc.local_addr, 0, sizeof(uh->uc.local_addr));
- memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr));
-
sl = sizeof(uh->uc.local_addr);
+ memset(&uh->uc.local_addr, 0, sl);
getsockname(fd, &uh->uc.local_addr.sa, &sl);
- getpeername(fd, &uh->uc.remote_addr.sa, &sl);
return 0;
}
static void uclient_http_reset_state(struct uclient_http *uh)
{
+ uh->seq++;
uclient_backend_reset_state(&uh->uc);
uh->read_chunked = -1;
uh->content_length = -1;
url->location, url->host);
blobmsg_for_each_attr(cur, uh->headers.head, rem)
- ustream_printf(uh->us, "%s: %s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
+ ustream_printf(uh->us, "%s: %s\r\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
if (uh->req_type == REQ_POST || uh->req_type == REQ_PUT)
ustream_printf(uh->us, "Transfer-Encoding: chunked\r\n");
static void __uclient_notify_read(struct uclient_http *uh)
{
struct uclient *uc = &uh->uc;
+ unsigned int seq = uh->seq;
char *data;
int len;
*sep = 0;
cur_len = sep + 2 - data;
uclient_parse_http_line(uh, data);
+ if (seq != uh->seq)
+ return;
+
ustream_consume(uh->us, cur_len);
len -= cur_len;
if (uh->eof)
return;
- if (uh->state == HTTP_STATE_RECV_DATA && uc->cb->data_read)
- uc->cb->data_read(uc);
+ if (uh->state == HTTP_STATE_RECV_DATA) {
+ /* Now it's uclient user turn to read some data */
+ uloop_timeout_cancel(&uc->connection_timeout);
+
+ if (uc->cb->data_read)
+ uc->cb->data_read(uc);
+ }
}
static void __uclient_notify_write(struct uclient_http *uh)
uh->ussl.notify_error = uclient_ssl_notify_error;
uh->ussl.notify_verify_error = uclient_ssl_notify_verify_error;
uh->ussl.notify_connected = uclient_ssl_notify_connected;
+ uh->ussl.server_name = uh->uc.url->host;
uh->ssl_ops->init(&uh->ussl, &uh->ufd.stream, uh->ssl_ctx, false);
uh->ssl_ops->set_peer_cn(&uh->ussl, uh->uc.url->host);
}
static int
-uclient_http_send_data(struct uclient *cl, char *buf, unsigned int len)
+uclient_http_send_data(struct uclient *cl, const char *buf, unsigned int len)
{
struct uclient_http *uh = container_of(cl, struct uclient_http, uc);
uclient_notify_eof(uh);
+ /* Now that we consumed something and if this isn't EOF, start timer again */
+ if (!uh->uc.eof && !cl->connection_timeout.pending)
+ uloop_timeout_set(&cl->connection_timeout, cl->timeout_msecs);
+
return len;
}