Changes in / [ef2ecec:4f086417] in mainline
- Location:
- uspace
- Files:
-
- 9 added
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/download/Makefile
ref2ecec r4f086417 29 29 USPACE_PREFIX = ../.. 30 30 LIBS = $(LIBHTTP_PREFIX)/libhttp.a $(LIBURI_PREFIX)/liburi.a 31 EXTRA_CFLAGS = -I$(LIBHTTP_PREFIX) -I$(LIBURI_PREFIX)31 EXTRA_CFLAGS = -I$(LIBHTTP_PREFIX)/include -I$(LIBURI_PREFIX) 32 32 DEFS = -DRELEASE=$(RELEASE) 33 33 BINARY = download -
uspace/app/download/main.c
ref2ecec r4f086417 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 } -
uspace/lib/http/Makefile
ref2ecec r4f086417 31 31 SLIBRARY = libhttp.so.0.0 32 32 LSONAME = libhttp.so0 33 #EXTRA_CFLAGS += 33 EXTRA_CFLAGS += -Iinclude 34 34 35 35 SOURCES = \ 36 http.c 36 src/http.c \ 37 src/headers.c \ 38 src/request.c \ 39 src/response.c \ 40 src/receive-buffer.c 37 41 38 42 include $(USPACE_PREFIX)/Makefile.common
Note:
See TracChangeset
for help on using the changeset viewer.