REQ_GET,
REQ_HEAD,
REQ_POST,
+ REQ_PUT,
__REQ_MAX
};
[REQ_GET] = "GET",
[REQ_HEAD] = "HEAD",
[REQ_POST] = "POST",
+ [REQ_PUT] = "PUT",
};
struct uclient_http {
if (uh->state >= HTTP_STATE_HEADERS_SENT)
return;
- if (uh->auth_type == AUTH_TYPE_UNKNOWN)
- req_type = REQ_HEAD;
-
ustream_printf(uh->us,
"%s %s HTTP/1.1\r\n"
"Host: %s\r\n",
blobmsg_for_each_attr(cur, uh->headers.head, rem)
ustream_printf(uh->us, "%s: %s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
- if (uh->req_type == REQ_POST)
+ if (uh->req_type == REQ_POST || uh->req_type == REQ_PUT)
ustream_printf(uh->us, "Transfer-Encoding: chunked\r\n");
uclient_http_add_auth_header(uh);
uh->uc.meta = uh->meta.head;
uclient_http_process_headers(uh);
- if (auth_type == AUTH_TYPE_UNKNOWN) {
+ if (auth_type == AUTH_TYPE_UNKNOWN && uh->uc.status_code == 401 &&
+ (uh->req_type == REQ_HEAD || uh->req_type == REQ_GET)) {
uclient_http_init_request(uh);
uclient_http_send_headers(uh);
uh->state = HTTP_STATE_REQUEST_DONE;
if (uh->state == HTTP_STATE_REQUEST_DONE) {
char *code;
+ if (!strlen(data))
+ return;
+
/* HTTP/1.1 */
strsep(&data, " ");
uc->cb->data_read(uc);
}
+static void __uclient_notify_write(struct uclient_http *uh)
+{
+ struct uclient *uc = &uh->uc;
+ uc->cb->data_sent(uc);
+}
+
static void uclient_notify_read(struct ustream *us, int bytes)
{
struct uclient_http *uh = container_of(us, struct uclient_http, ufd.stream);
__uclient_notify_read(uh);
}
+static void uclient_notify_write(struct ustream *us, int bytes)
+{
+ struct uclient_http *uh = container_of(us, struct uclient_http, ufd.stream);
+
+ __uclient_notify_write(uh);
+}
+
static void uclient_notify_state(struct ustream *us)
{
struct uclient_http *uh = container_of(us, struct uclient_http, ufd.stream);
us->string_data = true;
us->notify_state = uclient_notify_state;
us->notify_read = uclient_notify_read;
+ us->notify_write = uclient_notify_write;
ret = uclient_do_connect(uh, "80");
if (ret)
__uclient_notify_read(uh);
}
+static void uclient_ssl_notify_write(struct ustream *us, int bytes)
+{
+ struct uclient_http *uh = container_of(us, struct uclient_http, ussl.stream);
+
+ __uclient_notify_write(uh);
+}
+
static void uclient_ssl_notify_state(struct ustream *us)
{
struct uclient_http *uh = container_of(us, struct uclient_http, ussl.stream);
us->string_data = true;
us->notify_state = uclient_ssl_notify_state;
us->notify_read = uclient_ssl_notify_read;
+ us->notify_write = uclient_ssl_notify_write;
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;
return -1;
uclient_http_send_headers(uh);
- if (uh->req_type == REQ_POST)
+ if (uh->req_type == REQ_POST || uh->req_type == REQ_PUT)
ustream_printf(uh->us, "0\r\n\r\n");
uh->state = HTTP_STATE_REQUEST_DONE;
read_len += sep + 2 - data;
data = sep + 2;
- if (!uh->read_chunked)
+ if (!uh->read_chunked) {
uh->eof = true;
+ uh->uc.data_eof = true;
+ }
}
if (len > data_end - data)
len = uh->content_length;
uh->content_length -= len;
- if (!uh->content_length)
+ if (!uh->content_length) {
uh->eof = true;
+ uh->uc.data_eof = true;
+ }
}
if (len > 0) {