Lines Matching refs:req
177 struct http_request *req = CONTAINER_OF(parser, in on_url() local
182 if (req->internal.response.http_cb && in on_url()
183 req->internal.response.http_cb->on_url) { in on_url()
184 req->internal.response.http_cb->on_url(parser, at, length); in on_url()
192 struct http_request *req = CONTAINER_OF(parser, in on_status() local
197 len = MIN(length, sizeof(req->internal.response.http_status) - 1); in on_status()
198 memcpy(req->internal.response.http_status, at, len); in on_status()
199 req->internal.response.http_status[len] = 0; in on_status()
200 req->internal.response.http_status_code = in on_status()
204 req->internal.response.http_status); in on_status()
206 if (req->internal.response.http_cb && in on_status()
207 req->internal.response.http_cb->on_status) { in on_status()
208 req->internal.response.http_cb->on_status(parser, at, length); in on_status()
217 struct http_request *req = CONTAINER_OF(parser, in on_header_field() local
225 req->internal.response.cl_present = true; in on_header_field()
230 if (req->internal.response.http_cb && in on_header_field()
231 req->internal.response.http_cb->on_header_field) { in on_header_field()
232 req->internal.response.http_cb->on_header_field(parser, at, in on_header_field()
244 struct http_request *req = CONTAINER_OF(parser, in on_header_value() local
249 if (req->internal.response.cl_present) { in on_header_value()
261 req->internal.response.content_length = num; in on_header_value()
264 req->internal.response.cl_present = false; in on_header_value()
267 if (req->internal.response.http_cb && in on_header_value()
268 req->internal.response.http_cb->on_header_value) { in on_header_value()
269 req->internal.response.http_cb->on_header_value(parser, at, in on_header_value()
280 struct http_request *req = CONTAINER_OF(parser, in on_body() local
284 req->internal.response.body_found = 1; in on_body()
285 req->internal.response.processed += length; in on_body()
287 NET_DBG("Processed %zd length %zd", req->internal.response.processed, in on_body()
290 if (req->internal.response.http_cb && in on_body()
291 req->internal.response.http_cb->on_body) { in on_body()
292 req->internal.response.http_cb->on_body(parser, at, length); in on_body()
296 if (!req->internal.response.body_frag_start) { in on_body()
297 req->internal.response.body_frag_start = (uint8_t *)at; in on_body()
301 req->internal.response.body_frag_len = req->internal.response.data_len - in on_body()
302 (req->internal.response.body_frag_start - req->internal.response.recv_buf); in on_body()
309 struct http_request *req = CONTAINER_OF(parser, in on_headers_complete() local
313 if (req->internal.response.http_cb && in on_headers_complete()
314 req->internal.response.http_cb->on_headers_complete) { in on_headers_complete()
315 req->internal.response.http_cb->on_headers_complete(parser); in on_headers_complete()
323 if ((req->method == HTTP_HEAD || req->method == HTTP_OPTIONS) && in on_headers_complete()
324 req->internal.response.content_length > 0) { in on_headers_complete()
336 struct http_request *req = CONTAINER_OF(parser, in on_message_begin() local
340 if (req->internal.response.http_cb && in on_message_begin()
341 req->internal.response.http_cb->on_message_begin) { in on_message_begin()
342 req->internal.response.http_cb->on_message_begin(parser); in on_message_begin()
346 http_method_str(req->method)); in on_message_begin()
353 struct http_request *req = CONTAINER_OF(parser, in on_message_complete() local
357 if (req->internal.response.http_cb && in on_message_complete()
358 req->internal.response.http_cb->on_message_complete) { in on_message_complete()
359 req->internal.response.http_cb->on_message_complete(parser); in on_message_complete()
363 http_method_str(req->method)); in on_message_complete()
365 req->internal.response.message_complete = 1; in on_message_complete()
372 struct http_request *req = CONTAINER_OF(parser, in on_chunk_header() local
376 if (req->internal.response.http_cb && in on_chunk_header()
377 req->internal.response.http_cb->on_chunk_header) { in on_chunk_header()
378 req->internal.response.http_cb->on_chunk_header(parser); in on_chunk_header()
386 struct http_request *req = CONTAINER_OF(parser, in on_chunk_complete() local
390 if (req->internal.response.http_cb && in on_chunk_complete()
391 req->internal.response.http_cb->on_chunk_complete) { in on_chunk_complete()
392 req->internal.response.http_cb->on_chunk_complete(parser); in on_chunk_complete()
419 static void http_report_null(struct http_request *req) in http_report_null() argument
421 if (req->internal.response.cb) { in http_report_null()
426 req->internal.response.http_status_code = 0; in http_report_null()
429 req->internal.response.processed = 0; in http_report_null()
430 req->internal.response.data_len = 0; in http_report_null()
431 req->internal.response.content_length = 0; in http_report_null()
432 req->internal.response.body_frag_start = NULL; in http_report_null()
433 memset(req->internal.response.http_status, 0, HTTP_STATUS_STR_SIZE); in http_report_null()
435 req->internal.response.cb(&req->internal.response, HTTP_DATA_FINAL, in http_report_null()
436 req->internal.user_data); in http_report_null()
441 static void http_report_complete(struct http_request *req) in http_report_complete() argument
443 if (req->internal.response.cb) { in http_report_complete()
444 NET_DBG("Calling callback for %zd len data", req->internal.response.data_len); in http_report_complete()
445 req->internal.response.cb(&req->internal.response, HTTP_DATA_FINAL, in http_report_complete()
446 req->internal.user_data); in http_report_complete()
451 static void http_report_progress(struct http_request *req) in http_report_progress() argument
453 if (req->internal.response.cb) { in http_report_progress()
455 req->internal.response.data_len); in http_report_progress()
457 req->internal.response.cb(&req->internal.response, HTTP_DATA_MORE, in http_report_progress()
458 req->internal.user_data); in http_report_progress()
462 static int http_wait_data(int sock, struct http_request *req, const k_timepoint_t req_end_timepoint) in http_wait_data() argument
494 received = zsock_recv(sock, req->internal.response.recv_buf + offset, in http_wait_data()
495 req->internal.response.recv_buf_len - offset, 0); in http_wait_data()
503 req->internal.response.data_len += received; in http_wait_data()
506 &req->internal.parser, &req->internal.parser_settings, in http_wait_data()
507 req->internal.response.recv_buf + offset, received); in http_wait_data()
513 if (offset >= req->internal.response.recv_buf_len) { in http_wait_data()
517 if (req->internal.response.message_complete) { in http_wait_data()
518 http_report_complete(req); in http_wait_data()
521 http_report_progress(req); in http_wait_data()
524 req->internal.response.data_len = 0; in http_wait_data()
525 req->internal.response.body_frag_start = NULL; in http_wait_data()
526 req->internal.response.body_frag_len = 0; in http_wait_data()
541 http_report_null(req); in http_wait_data()
555 int http_client_req(int sock, struct http_request *req, in http_client_req() argument
568 if (sock < 0 || req == NULL || req->response == NULL || in http_client_req()
569 req->recv_buf == NULL || req->recv_buf_len == 0) { in http_client_req()
573 memset(&req->internal.response, 0, sizeof(req->internal.response)); in http_client_req()
575 req->internal.response.http_cb = req->http_cb; in http_client_req()
576 req->internal.response.cb = req->response; in http_client_req()
577 req->internal.response.recv_buf = req->recv_buf; in http_client_req()
578 req->internal.response.recv_buf_len = req->recv_buf_len; in http_client_req()
579 req->internal.user_data = user_data; in http_client_req()
580 req->internal.sock = sock; in http_client_req()
582 method = http_method_str(req->method); in http_client_req()
586 " ", req->url, " ", req->protocol, in http_client_req()
594 if (req->port) { in http_client_req()
596 &send_buf_pos, req_end_timepoint, "Host", ": ", req->host, in http_client_req()
597 ":", req->port, HTTP_CRLF, NULL); in http_client_req()
606 &send_buf_pos, req_end_timepoint, "Host", ": ", req->host, in http_client_req()
616 if (req->optional_headers_cb) { in http_client_req()
625 ret = req->optional_headers_cb(sock, req, user_data); in http_client_req()
632 for (i = 0; req->optional_headers && req->optional_headers[i]; in http_client_req()
636 req->optional_headers[i], NULL); in http_client_req()
645 for (i = 0; req->header_fields && req->header_fields[i]; i++) { in http_client_req()
647 &send_buf_pos, req_end_timepoint, req->header_fields[i], in http_client_req()
656 if (req->content_type_value) { in http_client_req()
659 req->content_type_value, HTTP_CRLF, NULL); in http_client_req()
667 if (req->payload || req->payload_cb) { in http_client_req()
668 if (req->payload_len) { in http_client_req()
672 "%zd", req->payload_len); in http_client_req()
702 if (req->payload_cb) { in http_client_req()
703 ret = req->payload_cb(sock, req, user_data); in http_client_req()
712 if (req->payload_len == 0) { in http_client_req()
713 length = strlen(req->payload); in http_client_req()
715 length = req->payload_len; in http_client_req()
718 ret = sendall(sock, req->payload, length, req_end_timepoint); in http_client_req()
746 http_client_init_parser(&req->internal.parser, in http_client_req()
747 &req->internal.parser_settings); in http_client_req()
750 total_recv = http_wait_data(sock, req, req_end_timepoint); in http_client_req()