]> granicus.if.org Git - libevent/commitdiff
Merge branch 'master' of https://github.com/libevent/libevent into https
authorAlexey Ozeritsky <aozeritsky@yandex-team.ru>
Sun, 14 Apr 2013 11:12:22 +0000 (15:12 +0400)
committerAlexey Ozeritsky <aozeritsky@yandex-team.ru>
Sun, 14 Apr 2013 11:12:22 +0000 (15:12 +0400)
1  2 
sample/https-client.c

index a9aded004eafa0bdde378d788d287998a55611d3,b32e430422afc003786f6e94ea9536ee5fe9b45a..99abc6925f11058b33437356c69bdd498393c503
@@@ -187,33 -183,12 +188,34 @@@ main(int argc, char **argv
        struct bufferevent *bev;
        struct evhttp_connection *evcon;
        struct evhttp_request *req;
+       struct evkeyvalq *output_headers;
  
 -      if (argc != 2)
 +      int i;
 +
 +      for (i = 1; i < argc; i++) {
 +              if (!strcmp("-url", argv[i])) {
 +                      if (i < argc - 1) {
 +                              url = argv[i + 1];
 +                      } else {
 +                              syntax();
 +                      }
 +              } else if (!strcmp("-ignore-cert", argv[i])) {
 +                      ignore_cert = 1;
 +              } else if (!strcmp("-data", argv[i])) {
 +                      if (i < argc - 1) {
 +                              data_file = argv[i + 1];
 +                      } else {
 +                              syntax();
 +                      }
 +              } else if (!strcmp("-help", argv[i])) {
 +                      syntax();
 +              }
 +      }
 +
 +      if (!url) {
                syntax();
 +      }
  
 -      url = argv[1];
        http_uri = evhttp_uri_parse(url);
        if (http_uri == NULL) {
                die("malformed url");
                return 1;
        }
  
-       evhttp_add_header(req->output_headers, "Host", host);
-       evhttp_add_header(req->output_headers, "Connection", "close");
+       output_headers = evhttp_request_get_output_headers(req);
+       evhttp_add_header(output_headers, "Host", host);
+       evhttp_add_header(output_headers, "Connection", "close");
  
 -      r = evhttp_make_request(evcon, req, EVHTTP_REQ_GET, uri);
 +      if (data_file) {
 +              FILE * f = fopen(data_file, "rb");
 +              char buf[1024];
 +              ssize_t s;
 +              size_t bytes = 0;
 +
 +              if (!f) {
 +                      syntax();
 +              }
 +
 +              while ((s = fread(buf, 1, sizeof(buf), f)) > 0) {
 +                      evbuffer_add(req->output_buffer, buf, s);
 +                      bytes += s;
 +              }
 +              snprintf(buf, sizeof(buf)-1, "%lu", bytes);
 +              evhttp_add_header(req->output_headers, "Content-Length", buf);
 +              fclose(f);
 +      }
 +
 +      r = evhttp_make_request(evcon, req, data_file ? EVHTTP_REQ_POST : EVHTTP_REQ_GET, uri);
        if (r != 0) {
                fprintf(stderr, "evhttp_make_request() failed\n");
                return 1;