Lines Matching refs:wsi
28 lws_client_http_body_pending(struct lws *wsi, int something_left_to_send)
30 wsi->client_http_body_pending = !!something_left_to_send;
34 lws_http_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd)
36 struct lws_context *context = wsi->a.context;
37 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
46 switch (lwsi_state(wsi)) {
53 lwsl_err("%s: %s: WAITING_DNS\n", __func__, lws_wsi_tag(wsi));
54 if (!lws_client_connect_2_dnsreq(wsi)) {
70 if (lws_client_connect_3_connect(wsi, NULL, NULL, 0, NULL) == NULL) {
82 switch (lws_socks5c_handle_state(wsi, pollfd, &cce)) {
104 lws_wsi_tag(wsi), pollfd->fd);
110 n = (int)recv(wsi->desc.sockfd, sb, context->pt_serv_buf_size, 0);
144 lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
166 if (lws_change_pollfd(wsi, LWS_POLLOUT, 0))
172 !(wsi->tls.use_ssl & LCCSCF_USE_SSL)
178 !(wsi->flags & LCCSCF_H2_PRIOR_KNOWLEDGE)
185 n = lws_client_create_tls(wsi, &cce, 1);
204 if (wsi->tls.use_ssl & LCCSCF_USE_SSL) {
205 n = lws_ssl_client_connect2(wsi, ebuf, sizeof(ebuf));
213 wsi->tls.ssl = NULL;
214 if (wsi->flags & LCCSCF_H2_PRIOR_KNOWLEDGE) {
216 lws_role_call_alpn_negotiated(wsi, "h2");
222 if (wsi->client_h2_alpn //&&
223 //lwsi_state(wsi) != LRS_H1C_ISSUE_HANDSHAKE2
241 if (wsi->client_h2_alpn)
242 if (lws_h2_issue_preface(wsi)) {
247 // lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE2);
248 lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND,
261 p = lws_generate_client_handshake(wsi, p);
263 if (wsi->role_ops == &role_ops_raw_skt
265 || wsi->role_ops == &role_ops_raw_file
271 lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS,
280 __func__, lws_wsi_tag(wsi),
281 (unsigned long)wsi->wsistate, wsi->desc.sockfd);
283 n = lws_ssl_capable_write(wsi, (unsigned char *)sb, lws_ptr_diff_size_t(p, sb));
287 lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS,
291 lws_callback_on_writable(wsi);
295 if (wsi->client_http_body_pending || lws_has_buffered_out(wsi)) {
297 lwsi_set_state(wsi, LRS_ISSUE_HTTP_BODY);
298 lws_set_timeout(wsi,
302 if (wsi->flags & LCCSCF_HTTP_X_WWW_FORM_URLENCODED)
303 lws_callback_on_writable(wsi);
305 if (wsi->http.proxy_clientside && wsi->parent &&
306 wsi->parent->http.buflist_post_body)
307 lws_callback_on_writable(wsi);
313 lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY);
314 wsi->hdr_parsing_completed = 0;
316 if (lwsi_state(wsi) == LRS_IDLING) {
317 lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY);
318 wsi->hdr_parsing_completed = 0;
320 wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART;
321 wsi->http.ah->lextable_pos = 0;
322 wsi->http.ah->unk_pos = 0;
324 wsi->http.ah->ues = URIES_IDLE;
328 lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
329 (int)wsi->a.context->timeout_secs);
331 lws_callback_on_writable(wsi);
337 if (wsi->http.proxy_clientside && wsi->parent &&
338 wsi->parent->http.buflist_post_body)
339 lws_callback_on_writable(wsi);
341 if (wsi->client_http_body_pending || lws_has_buffered_out(wsi)) {
342 //lws_set_timeout(wsi,
351 wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART;
352 wsi->http.ah->lextable_pos = 0;
353 wsi->http.ah->unk_pos = 0;
355 lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY);
356 lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
368 if (lws_buflist_total_len(&wsi->buflist))
369 lws_set_timeout(wsi, PENDING_TIMEOUT_CLOSE_ACK, 3);
372 lws_wsi_tag(wsi), pollfd->fd);
379 if (lws_change_pollfd(wsi, LWS_POLLOUT, 0))
402 while (wsi->http.ah->parser_state != WSI_PARSING_COMPLETE) {
408 buffered = lws_buflist_aware_read(pt, wsi, &eb, 0, __func__);
421 if (lws_parse(wsi, eb.token, &n)) {
430 lws_ss_handle_t *h = (lws_ss_handle_t *)lws_get_opaque_user_data(wsi);
438 (wsi->http.ah->parser_state ==
443 if (lws_buflist_aware_finished_consuming(wsi, &eb, m,
456 assert(wsi->http.ah->parser_state ==
468 if (wsi->http.ah->parser_state != WSI_PARSING_COMPLETE)
477 return lws_client_interpret_server_handshake(wsi);
481 __func__, lws_wsi_tag(wsi), lwsi_state(wsi));
486 lws_inform_client_conn_fail(wsi, (void *)cce, strlen(cce));
488 lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "cbail3");
501 lws_http_transaction_completed_client(struct lws *wsi)
503 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi];
506 lwsl_info("%s: %s (%s)\n", __func__, lws_wsi_tag(wsi),
507 wsi->a.protocol->name);
509 // if (wsi->http.ah && wsi->http.ah->http_response)
511 lws_metrics_caliper_report(wsi->cal_conn, METRES_GO);
513 if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi,
515 wsi->user_space, NULL, 0)) {
517 __func__, (unsigned long)lwsi_role(wsi));
521 wsi->http.rx_content_length = 0;
524 * For h1, wsi may pass some assets on to a queued child and be
528 n = _lws_generic_transaction_completed_active_conn(&wsi, 1);
531 if (wsi->http.ah) {
532 if (wsi->client_mux_substream)
538 __lws_header_table_detach(wsi, 0);
541 _lws_header_table_reset(wsi->http.ah);
544 if (!n || !wsi->http.ah)
553 lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY);
555 wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART;
556 wsi->http.ah->lextable_pos = 0;
557 wsi->http.ah->unk_pos = 0;
559 lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
560 (int)wsi->a.context->timeout_secs);
563 wsi->http.ah->ues = URIES_IDLE;
564 lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE2);
566 lwsl_info("%s: %s: new queued transaction\n", __func__, lws_wsi_tag(wsi));
567 lws_callback_on_writable(wsi);
573 lws_http_client_http_response(struct lws *wsi)
575 if (wsi->http.ah && wsi->http.ah->http_response)
576 return wsi->http.ah->http_response;
585 lws_http_is_redirected_to_get(struct lws *wsi)
587 return wsi->redirected_to_get;
591 lws_client_interpret_server_handshake(struct lws *wsi)
597 struct lws *nwsi = lws_get_network_wsi(wsi);
602 // lws_free_set_NULL(wsi->stash);
605 wsi->conmon.ciu_txn_resp = (lws_conmon_interval_us_t)
606 (lws_now_usecs() - wsi->conmon_datum);
609 ah = wsi->http.ah;
610 if (!wsi->do_ws) {
614 if (wsi->client_h2_alpn || wsi->client_mux_substream) {
616 __func__, lws_wsi_tag(wsi));
617 lws_role_transition(wsi, LWSIFR_CLIENT,
625 __func__, lws_wsi_tag(wsi));
626 lws_role_transition(wsi, LWSIFR_CLIENT,
634 wsi->http.ah = ah;
640 if ((wsi->flags & LCCSCF_CACHE_COOKIES) &&
641 lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_SET_COOKIE))
642 lws_parse_set_cookie(wsi);
658 wsi->http.conn_type = HTTP_CONNECTION_KEEP_ALIVE;
659 if (!wsi->client_mux_substream) {
660 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP);
662 if (wsi->do_ws && !p) {
669 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP1_0);
670 wsi->http.conn_type = HTTP_CONNECTION_CLOSE;
679 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_STATUS);
698 if (!wsi->client_no_follow_redirect &&
700 !wsi->http.proxy_clientside &&
703 p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_LOCATION);
710 if (wsi->conmon.pcol == LWSCONMON_PCOL_NONE) {
711 wsi->conmon.pcol = LWSCONMON_PCOL_HTTP;
712 wsi->conmon.protocol_specific.http.response = n;
716 if (wsi->for_ss
718 && !wsi->client_bound_sspc
722 lws_ss_handle_t *h = (lws_ss_handle_t *)lws_get_opaque_user_data(wsi);
732 if (wsi->a.protocol->callback(wsi,
734 wsi->user_space, p, (unsigned int)n)) {
746 char *mp = lws_hdr_simple_ptr(wsi,_WSI_TOKEN_CLIENT_METHOD);
747 int ml = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_METHOD);
752 wsi->redirected_to_get = 1;
753 wsi->http.ah->frags[wsi->http.ah->frag_index[
763 ads = lws_hdr_simple_ptr(wsi,
788 ads = lws_hdr_simple_ptr(wsi,
790 port = wsi->c_port;
793 if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI))
794 lws_strncpy(new_path, lws_hdr_simple_ptr(wsi,
809 if ((wsi->tls.use_ssl & LCCSCF_USE_SSL) && !ssl &&
810 !(wsi->flags & LCCSCF_ACCEPT_TLS_DOWNGRADE_REDIRECTS)) {
821 if (!lws_client_reset(&wsi, ssl, ads, port, path, ads, 1)) {
829 * ourselves from the current wsi usage, eg, h2 mux cleanly.
835 opaque = wsi->a.opaque_user_data;
836 lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "redir");
837 wsi->a.opaque_user_data = opaque;
844 if (!wsi->client_h2_alpn && !wsi->client_mux_substream) {
846 if (wsi->http.conn_type == HTTP_CONNECTION_KEEP_ALIVE)
847 wsi->keepalive_active = 1;
863 wsi->keepalive_rejected = 1;
865 lws_vhost_lock(wsi->a.vhost);
868 wsi->dll2_cli_txn_queue_owner.head) {
892 lws_vhost_unlock(wsi->a.vhost);
897 wsi->http.perform_rewrite = 0;
898 if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE)) {
899 if (!strncmp(lws_hdr_simple_ptr(wsi,
902 wsi->http.perform_rewrite = 0;
907 wsi->chunked = 0;
908 wsi->chunk_remaining = 0; /* ie, next thing is chunk size */
909 if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_TRANSFER_ENCODING)) {
910 simp = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_TRANSFER_ENCODING);
915 wsi->chunked = !strcmp(simp, "chunked");
917 wsi->chunk_parser = ELCP_HEX;
920 wsi->http.content_length_given = 0;
921 if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) {
922 simp = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH);
928 wsi->http.rx_content_length = (lws_filepos_t)atoll(simp);
931 wsi->http.rx_content_length);
932 wsi->http.rx_content_remain =
933 wsi->http.rx_content_length;
934 wsi->http.content_length_given = 1;
936 if (!wsi->chunked)
937 wsi->http.conn_type = HTTP_CONNECTION_CLOSE;
941 if (wsi->do_ws) {
947 if (wsi->a.protocol->callback(wsi,
949 wsi->user_space, NULL, 0)) {
956 if (lws_ensure_user_space(wsi)) {
957 lwsl_err("Problem allocating wsi user mem\n");
967 ah1 = wsi->http.ah;
968 wsi->http.ah = ah;
969 if (wsi->a.protocol->callback(wsi,
971 wsi->user_space, NULL, 0)) {
972 wsi->http.ah = ah1;
978 lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
980 wsi->rxflow_change_to = LWS_RXFLOW_ALLOW;
983 if (wsi->a.protocol->callback(wsi,
985 wsi->user_space, NULL, 0)) {
986 wsi->http.ah = ah1;
991 wsi->http.ah = ah1;
993 lwsl_info("%s: %s: client conn up\n", __func__, lws_wsi_tag(wsi));
1001 if (!wsi->mux_substream && !wsi->client_mux_substream &&
1002 lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH) &&
1003 !wsi->http.rx_content_length)
1004 return !!lws_http_transaction_completed_client(wsi);
1025 switch (lws_client_ws_upgrade(wsi, &cce)) {
1039 if (wsi->a.protocol) {
1044 lws_inform_client_conn_fail(wsi, (void *)cce, (unsigned int)n);
1048 "due to bail2 connection error: %s\n", wsi->a.protocol ?
1049 wsi->a.protocol->name : "unknown", cce);
1052 lws_close_free_wsi(wsi, (enum lws_close_status)close_reason, "c hs interp");
1063 lws_http_multipart_headers(struct lws *wsi, uint8_t *p)
1068 if (lws_get_random(wsi->a.context, (uint8_t *)buf, sizeof(buf)) !=
1073 wsi->http.multipart_boundary,
1074 sizeof(wsi->http.multipart_boundary));
1077 wsi->http.multipart_boundary);
1079 if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE,
1083 wsi->http.multipart = wsi->http.multipart_issue_boundary = 1;
1084 lws_client_http_body_pending(wsi, 1);
1090 lws_client_http_multipart(struct lws *wsi, const char *name,
1098 assert(wsi->http.multipart);
1103 wsi->http.multipart_boundary);
1108 if (wsi->client_subsequent_mime_part)
1110 wsi->client_subsequent_mime_part = 1;
1115 wsi->http.multipart_boundary, name);
1130 lws_generate_client_handshake(struct lws *wsi, char *pkt)
1132 const char *meth, *pp = lws_hdr_simple_ptr(wsi,
1134 char *p = pkt, *p1, *end = p + wsi->a.context->pt_serv_buf_size;
1136 meth = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_METHOD);
1139 wsi->do_ws = 1;
1141 wsi->do_ws = 0;
1145 lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
1151 pr = lws_vhost_name_to_protocol(wsi->a.vhost, pp);
1159 lws_bind_protocol(wsi, pr, __func__);
1162 if ((wsi->a.protocol->callback)(wsi, LWS_CALLBACK_RAW_ADOPT,
1163 wsi->user_space, NULL, 0))
1166 lws_role_transition(wsi, LWSIFR_CLIENT, LRS_ESTABLISHED,
1168 lws_header_table_detach(wsi, 1);
1186 path = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI);
1188 if (wsi->stash && wsi->stash->cis[CIS_PATH] &&
1189 wsi->stash->cis[CIS_PATH][0])
1190 path = wsi->stash->cis[CIS_PATH];
1204 lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_HOST));
1206 if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN)) {
1207 if (lws_check_opt(wsi->a.context->options,
1211 lws_hdr_simple_ptr(wsi,
1216 wsi->flags & LCCSCF_USE_SSL ?
1218 lws_hdr_simple_ptr(wsi,
1222 if (wsi->flags & LCCSCF_HTTP_MULTIPART_MIME) {
1223 p1 = (char *)lws_http_multipart_headers(wsi, (uint8_t *)p);
1230 if (wsi->parent &&
1231 lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH)) {
1234 lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH));
1235 if (atoi(lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH)))
1236 wsi->client_http_body_pending = 1;
1238 if (wsi->parent &&
1239 lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_AUTHORIZATION)) {
1242 lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_AUTHORIZATION));
1244 if (wsi->parent &&
1245 lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_CONTENT_TYPE)) {
1248 lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_TYPE));
1253 if (wsi->do_ws) {
1255 // if (!wsi->client_pipeline)
1257 p = lws_generate_client_ws_handshake(wsi, p, conn1);
1261 if (!wsi->client_pipeline)
1268 if (wsi->flags & LCCSCF_CACHE_COOKIES)
1269 lws_cookie_send_cookies(wsi, &p, end);
1272 if (wsi->a.protocol->callback(wsi,
1274 wsi->user_space, &p,
1275 (unsigned int)((pkt + wsi->a.context->pt_serv_buf_size) - p - 12)))
1278 if (wsi->flags & LCCSCF_HTTP_X_WWW_FORM_URLENCODED) {
1280 p += lws_snprintf(p, lws_ptr_diff_size_t(end, p), "Content-Length: %lu\x0d\x0a", wsi->http.writeable_len);
1281 lws_client_http_body_pending(wsi, 1);
1286 if (wsi->client_http_body_pending || lws_has_buffered_out(wsi))
1287 lws_callback_on_writable(wsi);
1289 lws_metrics_caliper_bind(wsi->cal_conn, wsi->a.context->mt_http_txn);
1291 wsi->conmon_datum = lws_now_usecs();
1326 lws_http_client_read(struct lws *wsi, char **buf, int *len)
1328 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi];
1343 buffered = lws_buflist_aware_read(pt, wsi, &eb, 0, __func__);
1353 // wsi->chunk_remaining);
1356 if (lws_change_pollfd(wsi, 0, LWS_POLLIN))
1362 if (wsi->http.ah &&
1363 wsi->http.ah->parser_state == WSI_PARSING_COMPLETE &&
1364 !lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH))
1371 if (lws_http_transaction_completed_client(wsi))
1385 wsi->client_rx_avail = 0;
1393 // wsi->chunk_remaining);
1394 while (wsi->chunked && (wsi->chunk_parser != ELCP_CONTENT) && *len) {
1395 switch (wsi->chunk_parser) {
1398 wsi->chunk_parser = ELCP_CR;
1406 wsi->chunk_remaining <<= 4;
1407 wsi->chunk_remaining |= n;
1414 if (wsi->chunk_remaining) {
1415 wsi->chunk_parser = ELCP_CONTENT;
1417 // wsi->chunk_remaining, *len);
1421 wsi->chunk_parser = ELCP_TRAILER_CR;
1435 wsi->chunk_parser = ELCP_POST_LF;
1445 wsi->chunk_parser = ELCP_HEX;
1446 wsi->chunk_remaining = 0;
1457 wsi->chunk_parser = ELCP_TRAILER_LF;
1480 if (wsi->chunked && !wsi->chunk_remaining)
1483 if (wsi->http.rx_content_remain &&
1484 wsi->http.rx_content_remain < (unsigned int)*len)
1485 n = (int)wsi->http.rx_content_remain;
1489 if (wsi->chunked && wsi->chunk_remaining &&
1490 wsi->chunk_remaining < n)
1491 n = wsi->chunk_remaining;
1495 if (wsi->http.perform_rewrite)
1496 lws_rewrite_parse(wsi->http.rw, (unsigned char *)*buf, n);
1502 !wsi->protocol_bind_balance ==
1503 !!wsi->http.proxy_clientside
1505 !!wsi->protocol_bind_balance
1510 q = user_callback_handle_rxflow(wsi->a.protocol->callback,
1511 wsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ,
1512 wsi->user_space, *buf, (unsigned int)n);
1525 if (wsi->chunked && wsi->chunk_remaining)
1526 wsi->chunk_remaining -= n;
1529 // wsi->chunk_remaining, *len);
1535 if (wsi->chunked && !wsi->chunk_remaining)
1536 wsi->chunk_parser = ELCP_POST_CR;
1538 if (wsi->chunked && *len)
1541 if (wsi->chunked)
1545 if (wsi->http.rx_content_length > 0)
1546 wsi->http.rx_content_remain -= (unsigned int)n;
1549 // wsi->http.rx_content_remain, wsi->http.rx_content_length,
1550 // wsi->http.content_length_given);
1552 if (wsi->http.rx_content_remain || !wsi->http.content_length_given)
1557 if (lws_http_transaction_completed_client(wsi)) {
1564 if (lws_buflist_aware_finished_consuming(wsi, &eb, consumed, buffered,
1581 * lws_client_reset() - retarget a connected wsi to start over with a new
1584 * wsi: connection to reset
1599 struct lws *wsi;
1606 wsi = *pwsi;
1607 pt = &wsi->a.context->pt[(int)wsi->tsi];
1609 lwsl_debug("%s: %s: redir %d: %s\n", __func__, lws_wsi_tag(wsi),
1610 wsi->redirects, address);
1612 if (wsi->redirects == 4) {
1616 wsi->redirects++;
1620 * but leave our wsi extant and still bound to whatever vhost it was
1632 cisin[n + 3] = lws_hdr_simple_ptr(wsi, hnames2[n]);
1635 cisin[CIS_ALPN] = wsi->alpn;
1638 if (lws_client_stash_create(wsi, cisin))
1648 wsi->c_port = (uint16_t)port;
1650 wsi->flags = (wsi->flags & (~LCCSCF_USE_SSL)) |
1664 __remove_wsi_socket_from_fds(wsi);
1669 ws = wsi->ws;
1670 wsi->ws = NULL;
1678 * We must use the copies in the wsi->stash instead if we want them.
1681 __lws_reset_wsi(wsi); /* detaches ah here */
1684 wsi->ws = ws;
1686 wsi->client_pipeline = 1;
1692 wsi->close_is_redirect = 1;