src/elastic-connection.c
int elastic_connection_post(struct elastic_connection *conn,
                            const char *path, string_t *data)
{
    FUNC_START();
    struct http_client_request *http_req = NULL;
    struct istream *post_payload = NULL;
    const char *method = "POST";

    if (conn == NULL || path == NULL || data == NULL) {
        i_error("fts_elastic: connection_post: critical error during POST");
        return -1;
    }

    if (conn->post_type == ELASTIC_POST_TYPE_DELETE) {
        method = "DELETE";
    }

    http_req = http_client_request(elastic_http_client, method, conn->http_host,
                                   path, elastic_connection_http_response, conn);
    http_client_request_set_port(http_req, conn->http_port);
    http_client_request_set_ssl(http_req, conn->http_ssl);
    /* XXX: should be application/x-ndjson for bulk updates, but why when this works? */
    http_client_request_add_header(http_req, "Content-Type", "application/json");
    if (conn->basic_auth_username != NULL && conn->basic_auth_pass != NULL) {
        http_client_request_set_auth_simple(http_req, conn->basic_auth_username, conn->basic_auth_pass);
    }

    post_payload = i_stream_create_from_buffer(data);
    http_client_request_set_payload(http_req, post_payload, TRUE);
    i_stream_unref(&post_payload);
    http_client_request_submit(http_req);

    conn->request_status = 0;
    http_client_wait(elastic_http_client);

    FUNC_END_RET_INT(conn->request_status);
    return conn->request_status;
}
/* Performs HTTP POST/DELETE request with callback */
Performs HTTP POST/DELETE request with callback
Performs HTTP POST / DELETE request with callback
int elastic_connection_post(struct elastic_connection *conn,
                            const char *path, string_t *data)
{
    FUNC_START();
    struct http_client_request *http_req = NULL;
    struct istream *post_payload = NULL;
    const char *method = "POST";
    if (conn == NULL || path == NULL || data == NULL) {
        i_error("fts_elastic: connection_post: critical error during POST");
        return -1;
    }
    if (conn->post_type == ELASTIC_POST_TYPE_DELETE) {
        method = "DELETE";
    }
    http_req = http_client_request(elastic_http_client, method, conn->http_host,
                                   path, elastic_connection_http_response, conn);
    http_client_request_set_port(http_req, conn->http_port);
    http_client_request_set_ssl(http_req, conn->http_ssl);
    http_client_request_add_header(http_req, "Content-Type", "application/json");
    if (conn->basic_auth_username != NULL && conn->basic_auth_pass != NULL) {
        http_client_request_set_auth_simple(http_req, conn->basic_auth_username, conn->basic_auth_pass);
    }
    post_payload = i_stream_create_from_buffer(data);
    http_client_request_set_payload(http_req, post_payload, TRUE);
    i_stream_unref(&post_payload);
    http_client_request_submit(http_req);
    conn->request_status = 0;
    http_client_wait(elastic_http_client);
    FUNC_END_RET_INT(conn->request_status);
    return conn->request_status;
}
int elastic_connection_post ( struct elastic_connection * conn , const char * path , string_t * data ) { FUNC_START ( ) ; struct http_client_request * http_req = NULL ; struct istream * post_payload = NULL ; const char * method = " " ; if ( conn == NULL || path == NULL || data == NULL ) { i_error ( " " ) ; return -1 ; } if ( conn -> post_type == ELASTIC_POST_TYPE_DELETE ) { method = " " ; } http_req = http_client_request ( elastic_http_client , method , conn -> http_host , path , elastic_connection_http_response , conn ) ; http_client_request_set_port ( http_req , conn -> http_port ) ; http_client_request_set_ssl ( http_req , conn -> http_ssl ) ; http_client_request_add_header ( http_req , " " , " " ) ; if ( conn -> basic_auth_username != NULL && conn -> basic_auth_pass != NULL ) { http_client_request_set_auth_simple ( http_req , conn -> basic_auth_username , conn -> basic_auth_pass ) ; } post_payload = i_stream_create_from_buffer ( data ) ; http_client_request_set_payload ( http_req , post_payload , TRUE ) ; i_stream_unref ( & post_payload ) ; http_client_request_submit ( http_req ) ; conn -> request_status = 0 ; http_client_wait ( elastic_http_client ) ; FUNC_END_RET_INT ( conn -> request_status ) ; return conn -> request_status ; }
Performs HTTP POST/DELETE request with callback
Performs HTTP POST / DELETE request with callback
/* XXX: should be application/x-ndjson for bulk updates, but why when this works? */