コード例 #1
0
ファイル: spdycli.c プロジェクト: life0fun/elephant
/*
 * Submits the request |req| to the connection |connection|.  This
 * function does not send packets; just append the request to the
 * internal queue in |connection->session|.
 */
static void submit_request(struct Connection *connection, struct Request *req)
{
  int pri = 0;
  int rv;
  const char *nv[17];
  /* We always use SPDY/3 style header even if the negotiated protocol
     version is SPDY/2. The library translates the header name as
     necessary. Make sure that the last item is NULL! */
  //nv[0] = ":method";     nv[1] = "GET";
  nv[0] = ":method";     nv[1] = "POST";
  nv[2] = ":path";       nv[3] = req->path;
  nv[4] = ":version";    nv[5] = "HTTP/1.1";
  nv[6] = ":scheme";     nv[7] = "https";
  nv[8] = ":host";       nv[9] = req->hostport;
  nv[10] = "accept";     nv[11] = "*/*";
  nv[12] = "user-agent"; nv[13] = "spdylay/"SPDYLAY_VERSION;
  nv[14] = "clientid";   nv[15] = "clientId-1234";
  nv[16] = NULL;
  spdylay_data_provider data_prd;
  data_prd.source.ptr = "client-1234";
  rv = spdylay_submit_request(connection->session, pri, nv, &data_prd, req);
  //rv = spdylay_submit_request(connection->session, pri, nv, NULL, req);
  if(rv != 0) {
    diec("spdylay_submit_request", rv);
  }
}
コード例 #2
0
ファイル: failmalloc_test.c プロジェクト: PiotrSikora/spdylay
static void run_spdylay_session_send(void)
{
  spdylay_session *session;
  spdylay_session_callbacks callbacks;
  const char *nv[] = { ":host", "example.org",
                       ":scheme", "https",
                       NULL };
  spdylay_data_provider data_prd;
  spdylay_settings_entry iv[2];
  my_user_data ud;
  int rv;
  memset(&callbacks, 0, sizeof(spdylay_session_callbacks));
  callbacks.send_callback = null_send_callback;
  callbacks.get_credential_ncerts = get_credential_ncerts;
  callbacks.get_credential_cert = get_credential_cert;
  callbacks.get_credential_proof = get_credential_proof;

  data_prd.read_callback = fixed_length_data_source_read_callback;
  ud.data_source_length = 64*1024;

  iv[0].settings_id = SPDYLAY_SETTINGS_UPLOAD_BANDWIDTH;
  iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_PERSIST_VALUE;
  iv[0].value = 256;
  iv[1].settings_id = SPDYLAY_SETTINGS_MAX_CONCURRENT_STREAMS;
  iv[1].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE;
  iv[1].value = 100;

  rv = spdylay_session_client_new(&session, SPDYLAY_PROTO_SPDY3,
                                  &callbacks, &ud);
  if(rv != 0) {
    goto client_new_fail;
  }
  rv = spdylay_submit_request(session, 3, nv, &data_prd, NULL);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_submit_syn_stream(session, SPDYLAY_CTRL_FLAG_NONE,
                                 0, 3, nv, NULL);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_session_send(session);
  if(rv != 0) {
    goto fail;
  }
  /* The SYN_STREAM submitted by the previous
     spdylay_submit_syn_stream will have stream ID 3. Send HEADERS to
     that stream. */
  rv = spdylay_submit_headers(session, SPDYLAY_CTRL_FLAG_NONE, 3, nv);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_submit_data(session, 3, SPDYLAY_DATA_FLAG_FIN, &data_prd);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_session_send(session);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_submit_rst_stream(session, 3, SPDYLAY_CANCEL);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_session_send(session);
  if(rv != 0) {
    goto fail;
  }
  /* Sending against half-closed stream */
  rv = spdylay_submit_headers(session, SPDYLAY_CTRL_FLAG_NONE, 3, nv);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_submit_data(session, 3, SPDYLAY_DATA_FLAG_FIN, &data_prd);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_submit_ping(session);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_submit_settings(session, SPDYLAY_FLAG_SETTINGS_NONE, iv, 2);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_session_send(session);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_submit_goaway(session, SPDYLAY_GOAWAY_OK);
  if(rv != 0) {
    goto fail;
  }
  rv = spdylay_session_send(session);
  if(rv != 0) {
    goto fail;
  }
 fail:
  spdylay_session_del(session);
 client_new_fail:
  ;
}
コード例 #3
0
ファイル: mhd2spdy_spdy.c プロジェクト: PavanKulk/httpserver
int
spdy_request(const char **nv,
             struct Proxy *proxy,
             bool with_body)
{
  int ret;
  uint16_t port;
  struct SPDY_Connection *connection;
  spdylay_data_provider post_data;

  if(glob_opt.only_proxy)
  {
    connection = glob_opt.spdy_connection;
  }
  else
  {
    connection = glob_opt.spdy_connections_head;
    while(NULL != connection)
    {
      if(0 == strcasecmp(proxy->uri->host, connection->host))
        break;
      connection = connection->next;
    }

    if(NULL == connection)
    {
      //connect to host
      port = proxy->uri->port;
      if(0 == port) port = 443;
      connection = spdy_connect(proxy->uri, port, true);
      if(NULL != connection)
      {
        DLL_insert(glob_opt.spdy_connections_head, glob_opt.spdy_connections_tail, connection);
        glob_opt.total_spdy_connections++;
      }
      else
        connection = glob_opt.spdy_connection;
    }
  }

  if(NULL == connection)
  {
    PRINT_INFO("there is no proxy!");
    return -1;
  }

  proxy->spdy_connection = connection;
  if(with_body)
  {
    post_data.source.ptr = proxy;
    post_data.read_callback = &spdy_cb_data_source_read;
    ret = spdylay_submit_request(connection->session, 0, nv, &post_data, proxy);
  }
  else
    ret = spdylay_submit_request(connection->session, 0, nv, NULL, proxy);

  if(ret != 0) {
    spdy_diec("spdylay_spdy_submit_request", ret);
  }
  PRINT_INFO2("adding proxy %i", proxy->id);
  if(NULL != connection->proxies_head)
    PRINT_INFO2("before proxy %i", connection->proxies_head->id);
  DLL_insert(connection->proxies_head, connection->proxies_tail, proxy);

  return ret;
}