示例#1
0
int http_request_parse(struct http_request_r *r,char p[1024])
{
	int n,i,header_length=0;
	char ch;

	strcat(r->buf,p);	

	n = strlen(r->buf);
	r->buf_size = n;
	for(i=0;i<n;i++)
	{
		ch = r->buf[i];
		//printf("%02x ",ch);
		if(ch=='\r' && n>i+3)
		{
			if(r->buf[i+1]=='\n' && r->buf[i+2]=='\r' && r->buf[i+3]=='\n')
			{
				header_length = i+4;
				break;
			}
		}
	}

	if(header_length>0)
	{
		//parse header
		r->content_pos = header_length;
		http_request_header_parse(r);
		if(r->content_length==n-header_length)
		{
			r->is_end = 1;
		}
		if(r->is_end==1)
		{
			http_request_line_parse(r);
	
			http_request_ext_path(r);
			
			http_request_header_fields_parse(r);
		}
	}

	return 0;
}
示例#2
0
} END_TEST

START_TEST(test_http_request_line_parse) 
{
    struct http_request_line rline;

    REQUEST_LINE_ASSERT_FAIL(rline, "");
    REQUEST_LINE_ASSERT_FAIL(rline, "   ");
    REQUEST_LINE_ASSERT_FAIL(rline, "   \r\n");
    REQUEST_LINE_ASSERT_FAIL(rline, "   \r\n  ");
    REQUEST_LINE_ASSERT_FAIL(rline, " http://hostname HTTP/1.1\r\n");
    REQUEST_LINE_ASSERT_FAIL(rline, "Invalid()Method http://hostname HTTP/1.1\r\n");
    REQUEST_LINE_ASSERT_FAIL(rline, "GET http://hostname Invalid version\r\n");
    REQUEST_LINE_ASSERT_FAIL(rline, "METHOD http://hostname HTTP/2.1");
    REQUEST_LINE_ASSERT_FAIL(rline, "METHOD ");
    REQUEST_LINE_ASSERT_FAIL(rline, "METHOD http://hostname");

    fail_unless(http_request_line_parse(&rline, "METHOD http://hostname HTTP/2.1\r\n") == 0);
    assert_str_msg(rline.method, "METHOD", rline.method);
    assert_uri(&rline.uri, "http://hostname", "http", NULL, "hostname", 0, NULL, NULL, NULL);
    ck_assert_int_eq(rline.version.major, 2);
    ck_assert_int_eq(rline.version.minor, 1);
    http_request_line_destroy(&rline);
} END_TEST