Commit 82ca4cf8 authored by Max Kellermann's avatar Max Kellermann

added InputStream.ready

The flag "ready" indicates whether the input stream is ready and it has parsed all meta data. Previously, it was impossible for decodeStart() to see the content type of HTTP input streams, because at that time, the HTTP response wasn't parsed yet.
parent 6120635f
...@@ -53,6 +53,18 @@ static void decodeStart(void) ...@@ -53,6 +53,18 @@ static void decodeStart(void)
dc.state = DECODE_STATE_START; dc.state = DECODE_STATE_START;
dc.command = DECODE_COMMAND_NONE; dc.command = DECODE_COMMAND_NONE;
/* wait for the input stream to become ready; its metadata
will be available then */
while (!inStream.ready) {
if (dc.command != DECODE_COMMAND_NONE)
goto stop;
ret = bufferInputStream(&inStream);
if (ret < 0)
goto stop;
}
/* for http streams, seekable is determined in bufferInputStream */ /* for http streams, seekable is determined in bufferInputStream */
dc.seekable = inStream.seekable; dc.seekable = inStream.seekable;
......
...@@ -31,6 +31,7 @@ void initInputStream(void) ...@@ -31,6 +31,7 @@ void initInputStream(void)
int openInputStream(InputStream * inStream, char *url) int openInputStream(InputStream * inStream, char *url)
{ {
inStream->ready = 0;
inStream->offset = 0; inStream->offset = 0;
inStream->size = 0; inStream->size = 0;
inStream->error = 0; inStream->error = 0;
......
...@@ -32,6 +32,8 @@ typedef int (*InputStreamAtEOFFunc) (InputStream * inStream); ...@@ -32,6 +32,8 @@ typedef int (*InputStreamAtEOFFunc) (InputStream * inStream);
typedef int (*InputStreamBufferFunc) (InputStream * inStream); typedef int (*InputStreamBufferFunc) (InputStream * inStream);
struct _InputStream { struct _InputStream {
int ready;
int error; int error;
long offset; long offset;
size_t size; size_t size;
......
...@@ -52,6 +52,8 @@ int inputStream_fileOpen(InputStream * inStream, char *filename) ...@@ -52,6 +52,8 @@ int inputStream_fileOpen(InputStream * inStream, char *filename)
inStream->atEOFFunc = inputStream_fileAtEOF; inStream->atEOFFunc = inputStream_fileAtEOF;
inStream->bufferFunc = inputStream_fileBuffer; inStream->bufferFunc = inputStream_fileBuffer;
inStream->ready = 1;
return 0; return 0;
} }
......
...@@ -598,6 +598,7 @@ found: ...@@ -598,6 +598,7 @@ found:
xclose(data->fd); xclose(data->fd);
data->fd = -1; data->fd = -1;
data->state = CONN_STATE_REDIRECT; data->state = CONN_STATE_REDIRECT;
is->ready = 1;
return 0; /* success */ return 0; /* success */
} }
return -1; return -1;
...@@ -696,6 +697,7 @@ static int recv_response(InputStream * is) ...@@ -696,6 +697,7 @@ static int recv_response(InputStream * is)
ringbuf_writer_reset(data->rb); ringbuf_writer_reset(data->rb);
data->state = CONN_STATE_PREBUFFER; data->state = CONN_STATE_PREBUFFER;
is->ready = 1;
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment