aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-07-04 22:30:21 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-07-04 22:30:21 +0200
commit81c4394cef92ca80116df197984025c286ea377d (patch)
tree83ecf77fe25a8fe48bcef0630ca3e95cd88c2d50
parent85b434ffc8870a592044b29686f6d2f352fe7c45 (diff)
downloadpgsql-http-bgworker-81c4394cef92ca80116df197984025c286ea377d.tar.gz
pgsql-http-bgworker-81c4394cef92ca80116df197984025c286ea377d.tar.bz2
pgsql-http-bgworker-81c4394cef92ca80116df197984025c286ea377d.tar.xz
pgsql-http-bgworker-81c4394cef92ca80116df197984025c286ea377d.zip
o Return a proper HTTP response.HEADmaster
o Less logging.
-rw-r--r--httpd.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/httpd.c b/httpd.c
index bc27936..b56cf40 100644
--- a/httpd.c
+++ b/httpd.c
@@ -111,7 +111,7 @@ static int start_query() {
elog(LOG, "SPI_execute_plan: SPI_result=%s", SPI_result_code_string(SPI_result));
return 1;
}
- elog(LOG, "SPI_execute_plan: SPI_processed=%d", SPI_processed);
+ elog(LOG, "SPI_execute_plan: SPI_processed=%d, SPI_tuptable=%p", SPI_processed, SPI_tuptable);
}
return 0;
@@ -162,14 +162,13 @@ static void continue_responding(ebb_connection *connection)
if(sql_state.is_cursor) {
SPI_cursor_fetch(sql_state.portal, true /* forward */, 3 /* count */);
- elog(LOG, "SPI_cursor_fetch: SPI_processed = %d, SPI_tuptable = %p", SPI_processed, SPI_tuptable);
+// elog(LOG, "SPI_cursor_fetch: SPI_processed = %d, SPI_tuptable = %p", SPI_processed, SPI_tuptable);
if(SPI_result != 0) {
elog(FATAL, "SPI_cursor_fetch: SPI_result: %s", SPI_result_code_string(SPI_result));
goto complete;
}
}
- elog(LOG, "SPI_cursor_fetch: SPI_processed = %d, SPI_tuptable = %p", SPI_processed, SPI_tuptable);
if(SPI_processed == 0 || SPI_tuptable == NULL) {
goto complete;
}
@@ -221,6 +220,8 @@ static void request_complete(ebb_request *request)
{
ebb_connection *connection;
int i;
+ StringInfoData buf;
+ TupleDesc tupleDesc;
//printf("request complete \n");
elog(LOG, "request complete");
@@ -234,26 +235,25 @@ static void request_complete(ebb_request *request)
connection_data->responses_to_write = 1;
*/
- if(start_query()) {
- StringInfoData buf;
+ initStringInfo(&buf);
- initStringInfo(&buf);
- appendStringInfo(&buf, "500 Internal Server Error: %s", SPI_result_code_string(SPI_result));
- appendStringInfoString(&buf, "Content-Length: 0");
+ if(start_query()) {
+ appendStringInfo(&buf, "HTTP/1.1 500 Internal Server Error: %s\r\n", SPI_result_code_string(SPI_result));
+ appendStringInfoString(&buf, "Content-Length: 0\r\n");
+ appendStringInfoString(&buf, "\r\n");
http_state.do_close = true;
ebb_connection_write(connection, buf.data, buf.len, continue_responding);
+
+ goto done;
}
- else {
- StringInfoData buf;
- TupleDesc tupleDesc;
- if(sql_state.is_cursor) {
- tupleDesc = sql_state.portal->tupDesc;
- }
- else {
- tupleDesc = SPI_tuptable->tupdesc;
- }
- initStringInfo(&buf);
+ appendStringInfoString(&buf, "HTTP/1.1 200 OK\r\n");
+ if(sql_state.is_cursor || SPI_tuptable) {
+ tupleDesc = sql_state.is_cursor ? sql_state.portal->tupDesc : SPI_tuptable->tupdesc;
+
+ appendStringInfoString(&buf, "Content-Type: text/csv\r\n");
+ appendStringInfoString(&buf, "\r\n");
+
for (i = 0; i < tupleDesc->natts; i++) {
if (tupleDesc->attrs[i]->attisdropped)
continue;
@@ -262,11 +262,17 @@ static void request_complete(ebb_request *request)
appendStringInfoChar(&buf, ';');
}
appendStringInfoString(&buf, NameStr(tupleDesc->attrs[i]->attname));
+ appendStringInfoString(&buf, "\r\n");
}
- appendStringInfoChar(&buf, '\r');
- appendStringInfoChar(&buf, '\n');
- ebb_connection_write(connection, buf.data, buf.len, continue_responding);
+ } else {
+ appendStringInfoString(&buf, "Content-Length: 0\r\n");
+ appendStringInfoString(&buf, "\r\n");
+ http_state.do_close = true;
}
+
+ ebb_connection_write(connection, buf.data, buf.len, continue_responding);
+
+done:
free(request);
}