| 295 st->write_chunk_buf_len = 0; |
295 st->write_chunk_buf_len = 0; |
| 296 st->write_chunk_buf_pos = 0; |
296 st->write_chunk_buf_pos = 0; |
| 297 st->chunked_enc = WS_FALSE; |
297 st->chunked_enc = WS_FALSE; |
| 298 st->read_eof = WS_TRUE; |
298 st->read_eof = WS_TRUE; |
| 299 st->write_eof = WS_FALSE; |
299 st->write_eof = WS_FALSE; |
| |
300 st->raw = WS_FALSE; |
| 300 return (IOStream*)st; |
301 return (IOStream*)st; |
| 301 } |
302 } |
| 302 |
303 |
| 303 void httpstream_free(IOStream *st) { |
304 void httpstream_free(IOStream *st) { |
| 304 HttpStream *http = (HttpStream*)st; |
305 HttpStream *http = (HttpStream*)st; |
| 582 if(read_data) { |
585 if(read_data) { |
| 583 // if we read data (and not a chunk header), we limit the |
586 // if we read data (and not a chunk header), we limit the |
| 584 // amount of bytes we copy |
587 // amount of bytes we copy |
| 585 size_t chunk_available = httpstr->max_read - httpstr->read; |
588 size_t chunk_available = httpstr->max_read - httpstr->read; |
| 586 cplen = cplen > chunk_available ? chunk_available : cplen; |
589 cplen = cplen > chunk_available ? chunk_available : cplen; |
| 587 httpstr->read += cplen; |
590 if(!httpstr->raw) { |
| |
591 httpstr->read += cplen; |
| |
592 } |
| 588 } |
593 } |
| 589 memcpy(buf, httpstr->readbuf + pos, cplen); |
594 memcpy(buf, httpstr->readbuf + pos, cplen); |
| 590 *httpstr->bufpos += cplen; |
595 *httpstr->bufpos += cplen; |
| 591 r += cplen; |
596 r += cplen; |
| 592 buf += cplen; |
597 buf += cplen; |
| 806 } |
811 } |
| 807 |
812 |
| 808 return rd; |
813 return rd; |
| 809 } |
814 } |
| 810 |
815 |
| 811 ssize_t net_http_read_raw(HttpStream *st, void *buf, size_t nbytes) { |
|
| 812 return st->fd->read(st->fd, buf, nbytes); |
|
| 813 } |
|
| 814 |
|
| 815 ssize_t net_http_sendfile(HttpStream *st, sendfiledata *sfd) { |
816 ssize_t net_http_sendfile(HttpStream *st, sendfiledata *sfd) { |
| 816 if(st->write_eof) return 0; |
817 if(st->write_eof) return 0; |
| 817 ssize_t ret = 0; |
818 ssize_t ret = 0; |
| 818 // TODO: support chunked transfer encoding |
819 // TODO: support chunked transfer encoding |
| 819 if(st->fd->sendfile) { |
820 if(st->fd->sendfile) { |