Compare commits
No commits in common. "f9e157293c8bbfe56d29218cbe3b2c6fdc1ea2ba" and "4938ee43bdcb7833e85f2cf942fa9e5d89d239ff" have entirely different histories.
f9e157293c
...
4938ee43bd
@ -1654,37 +1654,15 @@ struct request_handler
|
||||
LIST_HEADER (struct request_handler)
|
||||
|
||||
/// Install ourselves as the handler for the request, if applicable.
|
||||
/// If the request contains data, check it against CONTENT_LENGTH.
|
||||
/// ("Transfer-Encoding: chunked" should be dechunked by the HTTP server,
|
||||
/// however it is possible that it mishandles this situation.)
|
||||
/// Sets @a continue_ to false if further processing should be stopped,
|
||||
/// meaning the request has already been handled.
|
||||
/// Note that starting the response before receiving all data denies you
|
||||
/// the option of returning error status codes based on the data.
|
||||
bool (*try_handle) (struct request *request,
|
||||
struct str_map *headers, bool *continue_);
|
||||
|
||||
/// Handle incoming data. "len == 0" means EOF.
|
||||
/// Returns false if there is no more processing to be done.
|
||||
/// EOF is never delivered on a network error (see client_read_loop()).
|
||||
// XXX: the EOF may or may not be delivered when the request is cut short:
|
||||
// - client_scgi delivers an EOF when it itself receives an EOF without
|
||||
// considering any mismatch, and it can deliver another one earlier
|
||||
// when the counter just goes down to 0... depends on what we return
|
||||
// from here upon the first occasion (whether we want to close).
|
||||
// - FCGI_ABORT_REQUEST /might/ not close the stdin and it /might/ cover
|
||||
// a CONTENT_LENGTH mismatch, since this callback wouldn't get invoked.
|
||||
// The FastCGI specification explicitly says to compare CONTENT_LENGTH
|
||||
// against the number of received bytes, which may only be smaller.
|
||||
//
|
||||
// We might want to adjust client_scgi and client_fcgi to not invoke
|
||||
// request_push(EOF) when CONTENT_LENGTH hasn't been reached and remove
|
||||
// the extra EOF generation from client_scgi (why is it there, does the
|
||||
// server keep the connection open, or is it just a precaution?)
|
||||
//
|
||||
// The finalization callback takes care of any needs to destruct data.
|
||||
// If we handle this reliably in all clients, try_handle won't have to,
|
||||
// as it will run in a stricter-than-CGI scenario.
|
||||
// FIXME: the EOF may or may not be delivered when request is cut short,
|
||||
// we should fix FastCGI not to deliver it on CONTENT_LENGTH mismatch
|
||||
bool (*push_cb) (struct request *request, const void *data, size_t len);
|
||||
|
||||
/// Destroy the handler's data stored in the request object
|
||||
@ -1806,9 +1784,7 @@ request_handler_json_rpc_push
|
||||
|
||||
// TODO: check buf.len against CONTENT_LENGTH; if it's less, then the
|
||||
// client hasn't been successful in transferring all of its data.
|
||||
// See also comment on request_handler::push_cb. For JSON-RPC, though,
|
||||
// it shouldn't matter as an incomplete request will be invalid and
|
||||
// clients have no reason to append unnecessary trailing bytes.
|
||||
// See also comment on request_handler::push_cb.
|
||||
|
||||
struct str response = str_make ();
|
||||
str_append (&response, "Status: 200 OK\n");
|
||||
@ -1925,13 +1901,8 @@ request_handler_static_try_handle
|
||||
char *path = xstrdup_printf ("%s%s", root, suffix);
|
||||
print_debug ("trying to statically serve %s", path);
|
||||
|
||||
// TODO: check that this is a regular file
|
||||
FILE *fp = fopen (path, "rb");
|
||||
struct stat st = {};
|
||||
if (fp && !fstat (fileno (fp), &st) && !S_ISREG (st.st_mode))
|
||||
{
|
||||
fclose (fp);
|
||||
fp = NULL;
|
||||
}
|
||||
if (!fp)
|
||||
{
|
||||
struct str response = str_make ();
|
||||
@ -1976,8 +1947,8 @@ request_handler_static_try_handle
|
||||
request_write (request, buf, len);
|
||||
fclose (fp);
|
||||
|
||||
// TODO: this should rather not be returned all at once but in chunks
|
||||
// (consider Transfer-Encoding); file read requests never return EAGAIN
|
||||
// TODO: this should rather not be returned all at once but in chunks;
|
||||
// file read requests never return EAGAIN
|
||||
// TODO: actual file data should really be returned by a callback when
|
||||
// the socket is writable with nothing to be sent (pumping the entire
|
||||
// file all at once won't really work if it's huge).
|
||||
@ -2424,15 +2395,14 @@ client_scgi_on_content (void *user_data, const void *data, size_t len)
|
||||
print_debug ("SCGI request got more data than CONTENT_LENGTH");
|
||||
return false;
|
||||
}
|
||||
// We're in a slight disagreement with the SCGI specification since
|
||||
// We're in a slight disagreement with the specification since
|
||||
// this tries to write output before it has read all the input
|
||||
if (!request_push (&self->request, data, len))
|
||||
return false;
|
||||
if ((self->remaining_content -= len))
|
||||
return true;
|
||||
|
||||
// Signalise end of input to the request handler
|
||||
return request_push (&self->request, NULL, 0);
|
||||
return (self->remaining_content -= len) != 0
|
||||
|| request_push (&self->request, NULL, 0);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
@ -2671,7 +2641,7 @@ client_co_process (struct co_context *self)
|
||||
}
|
||||
|
||||
static void
|
||||
client_co_parse (struct co_context *self, const char *data, size_t len,
|
||||
backend_co_parse (struct co_context *self, const char *data, size_t len,
|
||||
size_t *n_parsed)
|
||||
{
|
||||
if (self->pending_fake_starter)
|
||||
@ -2696,12 +2666,12 @@ client_co_parse (struct co_context *self, const char *data, size_t len,
|
||||
}
|
||||
|
||||
static void
|
||||
client_co_on_data (struct co_context *self, const char *data, size_t len)
|
||||
backend_co_on_data (struct co_context *self, const char *data, size_t len)
|
||||
{
|
||||
size_t n_parsed = 0;
|
||||
do
|
||||
{
|
||||
client_co_parse (self, data, len, &n_parsed);
|
||||
backend_co_parse (self, data, len, &n_parsed);
|
||||
data += n_parsed;
|
||||
}
|
||||
while ((len -= n_parsed));
|
||||
@ -2730,7 +2700,7 @@ client_co_run (struct server_context *ctx)
|
||||
int errno_saved = errno;
|
||||
|
||||
if (buf.len)
|
||||
client_co_on_data (&self, buf.str, buf.len);
|
||||
backend_co_on_data (&self, buf.str, buf.len);
|
||||
if (result == SOCKET_IO_ERROR)
|
||||
exit_fatal ("read: %s", strerror (errno_saved));
|
||||
if (result == SOCKET_IO_EOF)
|
||||
|
Loading…
x
Reference in New Issue
Block a user