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