libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit f49028e96f9165b653a966f0455aee54346a3faa
parent e354fc772d0c8403aee0bf99f5acc75256e6eadc
Author: Andrey Uzunov <andrey.uzunov@gmail.com>
Date:   Wed, 19 Jun 2013 10:52:50 +0000

spdy: ignore POST instead of abort and send 501 no implemented

Diffstat:
Msrc/microspdy/applicationlayer.c | 38++++++++++++++++++++++++++++++++++++++
Msrc/microspdy/session.c | 38+++++++++++++++++++++++++++++++++++---
2 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/src/microspdy/applicationlayer.c b/src/microspdy/applicationlayer.c @@ -31,6 +31,22 @@ #include "session.h" +void +spdy_callback_response_done(void *cls, + struct SPDY_Response *response, + struct SPDY_Request *request, + enum SPDY_RESPONSE_RESULT status, + bool streamopened) +{ + (void)cls; + (void)status; + (void)streamopened; + + SPDY_destroy_request(request); + SPDY_destroy_response(response); +} + + /** * Callback called when new stream is created. It extracts the info from * the stream to create (HTTP) request object and pass it to the client. @@ -136,6 +152,28 @@ spdy_handler_new_stream (void *cls, return SPDY_YES; } + + //ignore everything but GET + if(strcasecmp("GET",method)) + { + SPDYF_DEBUG("received method '%s'", method); + static char * html = "Method not implemented. libmicrospdy supports now only GET."; + struct SPDY_Response *response = SPDY_build_response(501, NULL, SPDY_HTTP_VERSION_1_1, NULL, html, strlen(html)); + if(NULL==response) + { + SPDY_destroy_request(request); + return SPDY_YES; + } + + if(SPDY_YES != SPDY_queue_response(request, response, true, false, &spdy_callback_response_done, NULL)) + { + SPDY_destroy_response(response); + SPDY_destroy_request(request); + } + + //SPDY_destroy_request(request); + return SPDY_YES; + } //call client's callback function to notify daemon->new_request_cb(daemon->cls, diff --git a/src/microspdy/session.c b/src/microspdy/session.c @@ -322,9 +322,40 @@ spdyf_handler_read_rst_stream (struct SPDY_Session *session) static void spdyf_handler_read_data (struct SPDY_Session *session) { - (void)session; - //TODO ignore data frames for now - SPDYF_PANIC("POST requests are Not yet implemented!"); + //just ignore the whole frame for now + struct SPDYF_Data_Frame * frame; + + SPDYF_ASSERT(SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER == session->status + || SPDY_SESSION_STATUS_WAIT_FOR_BODY == session->status, + "the function is called wrong"); + + SPDYF_DEBUG("DATA frame received (POST?). Ignoring"); + + //SPDYF_SIGINT(""); + + frame = (struct SPDYF_Data_Frame *)session->frame_handler_cls; + + //handle subheaders + if(SPDY_SESSION_STATUS_WAIT_FOR_SUBHEADER == session->status) + { + if(frame->length > SPDY_MAX_SUPPORTED_FRAME_SIZE) + { + session->status = SPDY_SESSION_STATUS_IGNORE_BYTES; + return; + } + else + session->status = SPDY_SESSION_STATUS_WAIT_FOR_BODY; + } + + //handle body + + if(session->read_buffer_offset - session->read_buffer_beginning + >= frame->length) + { + session->read_buffer_beginning += frame->length; + session->status = SPDY_SESSION_STATUS_WAIT_FOR_HEADER; + free(frame); + } } @@ -1071,6 +1102,7 @@ SPDYF_session_idle (struct SPDY_Session *session) session->read_buffer + session->read_buffer_beginning, sizeof(struct SPDYF_Data_Frame)); session->read_buffer_beginning += sizeof(struct SPDYF_Data_Frame); + SPDYF_DATA_FRAME_NTOH(data_frame); session->status = SPDY_SESSION_STATUS_WAIT_FOR_BODY; session->frame_handler = &spdyf_handler_read_data;