Changes in uspace/app/download/main.c [d7b7f5e:cbfc8b7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/download/main.c
rd7b7f5e rcbfc8b7 47 47 #include <net/socket.h> 48 48 49 #include <http .h>49 #include <http/http.h> 50 50 #include <uri.h> 51 51 … … 132 132 fprintf(stderr, "Failed creating request\n"); 133 133 uri_destroy(uri); 134 free(server_path);135 134 return 3; 136 135 } 137 136 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 } 155 150 156 151 http_t *http = http_create(uri->host, port); 157 152 if (http == NULL) { 158 153 uri_destroy(uri); 159 free(server_path);160 154 fprintf(stderr, "Failed creating HTTP object\n"); 161 155 return 3; 162 156 } 163 157 164 intrc = http_connect(http);158 rc = http_connect(http); 165 159 if (rc != EOK) { 166 160 fprintf(stderr, "Failed connecting: %s\n", str_error(rc)); 167 161 uri_destroy(uri); 168 free(server_path);169 162 return rc; 170 163 } … … 174 167 fprintf(stderr, "Failed sending request: %s\n", str_error(rc)); 175 168 uri_destroy(uri); 176 free(server_path);177 169 return rc; 178 170 } 179 171 180 172 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); 182 175 if (rc != EOK) { 183 176 fprintf(stderr, "Failed receiving response: %s\n", str_error(rc)); 184 177 uri_destroy(uri); 185 free(server_path);186 178 return rc; 187 179 } … … 197 189 fprintf(stderr, "Failed allocating buffer\n)"); 198 190 uri_destroy(uri); 199 free(server_path);200 191 return ENOMEM; 201 192 } 202 193 203 194 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) { 205 196 fwrite(buf, 1, body_size, stdout); 206 197 } … … 212 203 213 204 uri_destroy(uri); 214 free(server_path);215 205 return EOK; 216 206 }
Note:
See TracChangeset
for help on using the changeset viewer.