Changeset 4f086417 in mainline for uspace/app/download/main.c


Ignore:
Timestamp:
2013-10-05T20:51:34Z (11 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
39bcc99
Parents:
ef2ecec (diff), cbfc8b7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libhttp improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/download/main.c

    ref2ecec r4f086417  
    4747#include <net/socket.h>
    4848
    49 #include <http.h>
     49#include <http/http.h>
    5050#include <uri.h>
    5151
     
    132132                fprintf(stderr, "Failed creating request\n");
    133133                uri_destroy(uri);
    134                 free(server_path);
    135134                return 3;
    136135        }
    137136       
    138         http_header_t *header_host = http_header_create("Host", uri->host);
    139         if (header_host == NULL) {
    140                 fprintf(stderr, "Failed creating Host header\n");
    141                 uri_destroy(uri);
    142                 free(server_path);
    143                 return 3;
    144         }
    145         list_append(&header_host->link, &req->headers);
    146        
    147         http_header_t *header_ua = http_header_create("User-Agent", USER_AGENT);
    148         if (header_ua == NULL) {
    149                 fprintf(stderr, "Failed creating User-Agent header\n");
    150                 uri_destroy(uri);
    151                 free(server_path);
    152                 return 3;
    153         }
    154         list_append(&header_ua->link, &req->headers);
     137        int rc = http_headers_append(&req->headers, "Host", uri->host);
     138        if (rc != EOK) {
     139                fprintf(stderr, "Failed setting Host header: %s\n", str_error(rc));
     140                uri_destroy(uri);
     141                return rc;
     142        }
     143       
     144        rc = http_headers_append(&req->headers, "User-Agent", USER_AGENT);
     145        if (rc != EOK) {
     146                fprintf(stderr, "Failed creating User-Agent header: %s\n", str_error(rc));
     147                uri_destroy(uri);
     148                return rc;
     149        }
    155150       
    156151        http_t *http = http_create(uri->host, port);
    157152        if (http == NULL) {
    158153                uri_destroy(uri);
    159                 free(server_path);
    160154                fprintf(stderr, "Failed creating HTTP object\n");
    161155                return 3;
    162156        }
    163157       
    164         int rc = http_connect(http);
     158        rc = http_connect(http);
    165159        if (rc != EOK) {
    166160                fprintf(stderr, "Failed connecting: %s\n", str_error(rc));
    167161                uri_destroy(uri);
    168                 free(server_path);
    169162                return rc;
    170163        }
     
    174167                fprintf(stderr, "Failed sending request: %s\n", str_error(rc));
    175168                uri_destroy(uri);
    176                 free(server_path);
    177169                return rc;
    178170        }
    179171       
    180172        http_response_t *response = NULL;
    181         rc = http_receive_response(http, &response);
     173        rc = http_receive_response(&http->recv_buffer, &response, 16 * 1024,
     174            100);
    182175        if (rc != EOK) {
    183176                fprintf(stderr, "Failed receiving response: %s\n", str_error(rc));
    184177                uri_destroy(uri);
    185                 free(server_path);
    186178                return rc;
    187179        }
     
    197189                        fprintf(stderr, "Failed allocating buffer\n)");
    198190                        uri_destroy(uri);
    199                         free(server_path);
    200191                        return ENOMEM;
    201192                }
    202193               
    203194                int body_size;
    204                 while ((body_size = http_receive_body(http, buf, buf_size)) > 0) {
     195                while ((body_size = recv_buffer(&http->recv_buffer, buf, buf_size)) > 0) {
    205196                        fwrite(buf, 1, body_size, stdout);
    206197                }
     
    212203       
    213204        uri_destroy(uri);
    214         free(server_path);
    215205        return EOK;
    216206}
Note: See TracChangeset for help on using the changeset viewer.