Ejemplo n.º 1
0
/* Sends REQ on socket SOCKFD. Returns the number of bytes which were sent,
 * and -1 on error. */
int kvrequest_send(kvrequest_t *kvreq, int sockfd) {
  char *method = http_method_for_request_type(kvreq->type);
  if (!method) return -1;

  struct url_params params;
  params.path = path_for_request_type(kvreq->type);
  params.key = kvreq->key;
  params.val = kvreq->val;

  char *url = url_encode(&params);
  struct http_outbound *msg = http_start_request(sockfd, method, url);
  if (!msg) return -1;
  free(url);

  http_end_headers(msg);
  return http_send_and_free(msg);
}
Ejemplo n.º 2
0
/* Sends REQ on socket SOCKFD. Returns the number of bytes which were sent, and
 * 1 on error. */
int kvrequest_send(kvrequest_t *kvreq, int sockfd) {
  http_method_t method = http_method_for_request_type(kvreq->type);
  if (method == INVALID)
    return -1;

  url_params_t params;
  strcpy(params.path, path_for_request_type(kvreq->type));
  strcpy(params.key, kvreq->key);
  strcpy(params.val, kvreq->val);

  char url[HTTP_MSG_MAX_SIZE + 1];
  url_encode(url, &params);

  http_outbound_t msg;
  if (!http_outbound_init_request(&msg, sockfd, method, url))
    return -1;

  http_outbound_end_headers(&msg);
  return http_outbound_send(&msg);
}