Skip to content

Commit

Permalink
Add mime type to pipeline and switch on response
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkReedZ committed Mar 13, 2024
1 parent cda4a3f commit 1bf077e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/mrhttp/internals/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ Protocol* Protocol_on_body(Protocol* self, char* body, size_t body_len) {
return Protocol_handle_request( self, self->request, r );
}

//? PyObject *ret = pipeline_queue(self, (PipelineRequest){true, self->request, task});
//? PyObject *ret = pipeline_queue(self, (PipelineRequest){true, 0, self->request, task});
}
if ( r->mrq ) { //TODO
DBG printf("Route uses mrq\n");
Expand Down Expand Up @@ -602,7 +602,7 @@ Protocol* Protocol_handle_request(Protocol* self, Request* request, Route* r) {
return self;
}
}
printf("Unhandled exception :\n");
printf("Unhandled exception in the page handler :\n");
PyObject_Print( type, stdout, 0 ); printf("\n");
if ( value ) { PyObject_Print( value, stdout, 0 ); printf("\n"); }
PyErr_Clear();
Expand All @@ -618,12 +618,11 @@ Protocol* Protocol_handle_request(Protocol* self, Request* request, Route* r) {


if ( r->iscoro ) {
response_setMimeType(r->mtype); // TODO this doesn't work if we pipeline different types

DBG printf("protocol - Request is a coroutine\n");
PyObject *task;
if(!(task = PyObject_CallFunctionObjArgs(self->create_task, result, NULL))) return NULL;
PyObject *ret = pipeline_queue(self, (PipelineRequest){true, request, task});
PyObject *ret = pipeline_queue(self, (PipelineRequest){true, r->mtype, request, task});
Py_XDECREF(task);
Py_DECREF(result);
if ( !ret ) return NULL;
Expand All @@ -632,7 +631,7 @@ Protocol* Protocol_handle_request(Protocol* self, Request* request, Route* r) {

if(!PIPELINE_EMPTY(self))
{
if(!pipeline_queue(self, (PipelineRequest){false, request, result})) goto error;
if(!pipeline_queue(self, (PipelineRequest){false, r->mtype, request, result})) goto error;
Py_DECREF(result);
return self;
}
Expand Down Expand Up @@ -823,7 +822,7 @@ static void* protocol_pipeline_ready(Protocol* self, PipelineRequest r)
}
PyErr_Clear();

printf("Unhandled exception:\n");
printf("Unhandled exception in coro page handler:\n");
PyObject_Print( type, stdout, 0 ); printf("\n");
PyObject_Print( value, stdout, 0 ); printf("\n");

Expand All @@ -843,6 +842,7 @@ static void* protocol_pipeline_ready(Protocol* self, PipelineRequest r)
//response = PyUnicode_FromEncodedObject( response, "utf-8", "strict" );
//printf("WARNING: Page handler should return a string. Bytes object returned from the page handler is being converted to unicode using utf-8\n");
//}
response_setMimeType(r.mtype);

//if ( !PyUnicode_Check( response ) ) {
if ( !( PyUnicode_Check( response ) || PyBytes_Check( response ) ) ) {
Expand Down
1 change: 1 addition & 0 deletions src/mrhttp/internals/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

typedef struct {
bool is_task;
int mtype;
Request* request;
PyObject* task; // Task if coroutine otherwise response output
} PipelineRequest;
Expand Down

0 comments on commit 1bf077e

Please sign in to comment.