comparison http.c @ 385:2f56d366a787 libavformat

no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
author michael
date Sun, 14 Mar 2004 02:59:33 +0000
parents 741c56c608bb
children 0fdc96c2f2fe
comparison
equal deleted inserted replaced
384:9479dac25620 385:2f56d366a787
181 181
182 /* send http header */ 182 /* send http header */
183 post = h->flags & URL_WRONLY; 183 post = h->flags & URL_WRONLY;
184 184
185 snprintf(s->buffer, sizeof(s->buffer), 185 snprintf(s->buffer, sizeof(s->buffer),
186 "%s %s HTTP/1.0\n" 186 "%s %s HTTP/1.0\r\n"
187 "User-Agent: %s\n" 187 "User-Agent: %s\r\n"
188 "Accept: */*\n" 188 "Accept: */*\r\n"
189 "Host: %s\n" 189 "Host: %s\r\n"
190 "\n", 190 "\r\n",
191 post ? "POST" : "GET", 191 post ? "POST" : "GET",
192 path, 192 path,
193 LIBAVFORMAT_IDENT, 193 LIBAVFORMAT_IDENT,
194 hoststr); 194 hoststr);
195 195
236 236
237 237
238 static int http_read(URLContext *h, uint8_t *buf, int size) 238 static int http_read(URLContext *h, uint8_t *buf, int size)
239 { 239 {
240 HTTPContext *s = h->priv_data; 240 HTTPContext *s = h->priv_data;
241 int size1, len; 241 int len;
242 242
243 size1 = size; 243 /* read bytes from input buffer first */
244 while (size > 0) { 244 len = s->buf_end - s->buf_ptr;
245 /* read bytes from input buffer first */ 245 if (len > 0) {
246 len = s->buf_end - s->buf_ptr; 246 if (len > size)
247 if (len > 0) { 247 len = size;
248 if (len > size) 248 memcpy(buf, s->buf_ptr, len);
249 len = size; 249 s->buf_ptr += len;
250 memcpy(buf, s->buf_ptr, len); 250 } else {
251 s->buf_ptr += len; 251 len = url_read(s->hd, buf, size);
252 } else { 252 }
253 len = url_read (s->hd, buf, size); 253 return len;
254 if (len < 0) {
255 return len;
256 } else if (len == 0) {
257 break;
258 }
259 }
260 size -= len;
261 buf += len;
262 }
263 return size1 - size;
264 } 254 }
265 255
266 /* used only when posting data */ 256 /* used only when posting data */
267 static int http_write(URLContext *h, uint8_t *buf, int size) 257 static int http_write(URLContext *h, uint8_t *buf, int size)
268 { 258 {