HTTPC_STATUS_T http_get_large(const HTTPC_SESSION_T* session,
                                       const char* url,
                                       HTTP_GET_CALLBACK_T getWriteCallback) {
    ASSERT(session != NULL);
	ASSERT(session->handle != NULL);

    wiced_result_t     http_return;
    session_info *     sinfo = (session_info *)(session->handle);
    HTTPC_STATUS_T return_value = HTTPC_ERROR;

	if (sinfo->hnd.is_connected == 0) {
		http_return = open_session(&sinfo->hnd , url);
	}

    http_return = http_stream_start_headers(&sinfo->hnd, HTTP_GET, url);
    if (http_return == WICED_SUCCESS) {
        if (sinfo->username_and_password != NULL) {
            http_return = http_send_basic_authorization(&sinfo->hnd,
                                                        sinfo->username_and_password);
            if (http_return == WICED_SUCCESS) {
                if ((sinfo->stg.req_hdr_stg.name  != NULL) &&
                    (sinfo->stg.req_hdr_stg.value != NULL)) {
                    http_header_t header = {
                        .name = sinfo->stg.req_hdr_stg.name,
                        .value = sinfo->stg.req_hdr_stg.value,
                    };

                    http_return = http_stream_add_headers(&sinfo->hnd, &header, 1);
                    if (http_return != WICED_SUCCESS) {
                        DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                                      "http_stream_add_headers failed. http_return = %d.\n",
                                      url, http_return);
                    }
                }
            } else {
                DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                              "http_send_basic_authorization failed. http_return = %d.\n",
                              url, http_return);
            }
        }
    } else {
        DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                      "http_stream_start_headers failed. http_return = %d.\n",
                      url, http_return);
    }
    if (http_return == WICED_SUCCESS) {
        http_return = http_stream_end_headers(&sinfo->hnd, WICED_TRUE);
        if (http_return == WICED_SUCCESS) {
            http_return = http_stream_flush(&sinfo->hnd);
            if (http_return == WICED_SUCCESS) {
                wiced_packet_t *packet;
                http_return = http_stream_receive(&sinfo->hnd, &packet, sinfo->session_timeout *
                    MS_PER_SECOND);
                if (http_return == WICED_SUCCESS) {
                    http_status_code_t response_code;
                    http_return = http_process_response(packet, &response_code);
                    if (http_return == WICED_SUCCESS) {
                        sinfo->result_code = response_code;
                        if (response_code >= 200 && response_code < 302) {
                            if (sinfo->result_code != HTTP_NO_CONTENT) {
                                if ((getWriteCallback != NULL)) {
                                    do {
                                        unsigned char *buffer;
                                        uint32_t size;
                                        http_return = http_get_body(packet,
                                                                    &buffer,
                                                                    &size);
                                        if (http_return == WICED_SUCCESS) {
                                            if (size > 0)
                                                if ((getWriteCallback(buffer,
                                                                      http_return,
                                                                      NULL)) == 0) {
                                                    DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                                                                  "getWriteCallback() returned error.\n");
                                                    break;
                                                }
                                        } else {
                                            DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                                                          "http_get_body failed. url = %s, http_return = %d.\n",
                                                          url, http_return);
                                        }
                                    } while (http_return > 0);
                                    //FIXME: Add checking of failed callback
                                    if (http_return == WICED_SUCCESS) {
                                        return_value = HTTPC_SUCCESS;
                                    }
                                } else {
                                    DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                                                  "http_get_large: getWriteCallback() is NULL.\n");
                                }
                            }
                        } else {
                            DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                                          "http request failed. url = %s, status_code = %d.\n",
                                          url, sinfo->result_code);
                        }
                    } else {
                        DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                                      "http_process_response failed. url = %s, http_return = %d.\n",
                                      url, http_return);
                    }
                } else {
                    DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                                  "http_stream_receive failed. url = %s, http_return = %d.\n",
                                  url, http_return);
                }
            } else {
                DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                              "http_stream_flush failed. url = %s, http_return = %d.\n",
                              url, http_return);
            }
        } else {
            DEBUG_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,
                          "http_stream_end_headers failed. http_return = %d.\n",
                          url, http_return);
        }
    }

    return return_value;
}