@@ -49,50 +49,54 @@ static bool s_on_body_stub(const struct aws_byte_cursor *data, bool finished, vo
4949 return true;
5050}
5151
52- static void s_on_uri (struct aws_byte_cursor * uri , void * user_data ) {
53- struct aws_byte_cursor * ptr = (struct aws_byte_cursor * )user_data ;
54- if (ptr ) {
55- size_t len = ptr -> len < uri -> len ? ptr -> len : uri -> len ;
56- memcpy (ptr -> ptr , uri -> ptr , len );
57- ptr -> len = len ;
58- }
59- }
60-
61- static void s_on_uri_stub (struct aws_byte_cursor * uri , void * user_data ) {
62- (void )uri ;
63- (void )user_data ;
64- }
65-
66- static void s_on_code (int code , void * user_data ) {
52+ static void s_on_response (int code , void * user_data ) {
6753 int * ptr = (int * )user_data ;
6854 if (ptr ) {
6955 * ptr = code ;
7056 }
7157}
7258
73- static void s_on_code_stub (int code , void * user_data ) {
59+ static void s_on_response_stub (int code , void * user_data ) {
7460 (void )code ;
7561 (void )user_data ;
7662}
7763
7864struct request_data {
7965 enum aws_http_method method_enum ;
8066 struct aws_byte_cursor method_str ;
67+ struct aws_byte_cursor uri ;
8168 uint8_t buffer [1024 ];
8269};
8370
84- static void s_on_method (enum aws_http_method method , const struct aws_byte_cursor * method_str , void * user_data ) {
71+ static void s_on_request (
72+ enum aws_http_method method_enum ,
73+ const struct aws_byte_cursor * method_str ,
74+ const struct aws_byte_cursor * uri ,
75+ void * user_data ) {
76+
8577 struct request_data * request_data = (struct request_data * )user_data ;
78+ assert (sizeof (request_data -> buffer ) >= uri -> len + method_str -> len );
8679 if (request_data ) {
87- request_data -> method_enum = method ;
80+ request_data -> method_enum = method_enum ;
81+
8882 memcpy (request_data -> buffer , method_str -> ptr , method_str -> len );
8983 request_data -> method_str = aws_byte_cursor_from_array (request_data -> buffer , method_str -> len );
84+
85+ uint8_t * uri_dst = request_data -> buffer + method_str -> len ;
86+ memcpy (uri_dst , uri -> ptr , uri -> len );
87+ request_data -> uri = aws_byte_cursor_from_array (uri_dst , uri -> len );
9088 }
9189}
9290
93- static void s_on_method_stub (enum aws_http_method method , const struct aws_byte_cursor * method_str , void * user_data ) {
94- (void )method ;
91+ static void s_on_request_stub (
92+ enum aws_http_method method_enum ,
93+ const struct aws_byte_cursor * method_str ,
94+ const struct aws_byte_cursor * uri ,
95+ void * user_data ) {
96+
97+ (void )method_enum ;
9598 (void )method_str ;
99+ (void )uri ;
96100 (void )user_data ;
97101}
98102
@@ -115,14 +119,13 @@ static void s_common_test_setup(
115119 params -> user_data = user_data ;
116120 params -> vtable .on_header = s_on_header_stub ;
117121 params -> vtable .on_body = s_on_body_stub ;
118- params -> vtable .on_uri = s_on_uri_stub ;
119- params -> vtable .on_code = s_on_code_stub ;
120- params -> vtable .on_method = s_on_method_stub ;
122+ params -> vtable .on_request = s_on_request_stub ;
123+ params -> vtable .on_response = s_on_response_stub ;
121124 params -> vtable .on_done = s_on_done ;
122125}
123126
124- AWS_TEST_CASE (http_test_get_method , s_http_test_get_method );
125- static int s_http_test_get_method (struct aws_allocator * allocator , void * ctx ) {
127+ AWS_TEST_CASE (http_test_get_request , s_http_test_get_request );
128+ static int s_http_test_get_request (struct aws_allocator * allocator , void * ctx ) {
126129 (void )ctx ;
127130
128131 struct request_data request_data ;
@@ -131,7 +134,7 @@ static int s_http_test_get_method(struct aws_allocator *allocator, void *ctx) {
131134
132135 struct aws_http_decoder_params params ;
133136 s_common_test_setup (allocator , 1024 , & params , s_request , & request_data );
134- params .vtable .on_method = s_on_method ;
137+ params .vtable .on_request = s_on_request ;
135138 struct aws_http_decoder * decoder = aws_http_decoder_new (& params );
136139
137140 size_t len = strlen (msg );
@@ -140,6 +143,8 @@ static int s_http_test_get_method(struct aws_allocator *allocator, void *ctx) {
140143
141144 ASSERT_TRUE (aws_byte_cursor_eq_c_str (& request_data .method_str , "HEAD" ));
142145
146+ ASSERT_TRUE (aws_byte_cursor_eq_c_str (& request_data .uri , "/" ));
147+
143148 aws_http_decoder_destroy (decoder );
144149 aws_http_library_clean_up ();
145150 return AWS_OP_SUCCESS ;
@@ -179,28 +184,6 @@ static int s_http_test_response_bad_version(struct aws_allocator *allocator, voi
179184 return AWS_OP_SUCCESS ;
180185}
181186
182- AWS_TEST_CASE (http_test_get_uri , s_http_test_get_uri );
183- static int s_http_test_get_uri (struct aws_allocator * allocator , void * ctx ) {
184- (void )ctx ;
185-
186- uint8_t buf [128 ];
187- struct aws_byte_cursor uri_data = aws_byte_cursor_from_array (buf , 128 );
188-
189- const char * msg = s_typical_request ;
190- struct aws_http_decoder_params params ;
191- s_common_test_setup (allocator , 1024 , & params , s_request , & uri_data );
192- params .vtable .on_uri = s_on_uri ;
193- struct aws_http_decoder * decoder = aws_http_decoder_new (& params );
194-
195- size_t len = strlen (msg );
196- ASSERT_SUCCESS (aws_http_decode (decoder , msg , len , NULL ));
197- ASSERT_TRUE (aws_byte_cursor_eq_c_str (& uri_data , "/" ));
198-
199- aws_http_decoder_destroy (decoder );
200- aws_http_library_clean_up ();
201- return AWS_OP_SUCCESS ;
202- }
203-
204187AWS_TEST_CASE (http_test_get_status_code , s_http_test_get_status_code );
205188static int s_http_test_get_status_code (struct aws_allocator * allocator , void * ctx ) {
206189 (void )ctx ;
@@ -210,7 +193,7 @@ static int s_http_test_get_status_code(struct aws_allocator *allocator, void *ct
210193 const char * msg = s_typical_response ;
211194 struct aws_http_decoder_params params ;
212195 s_common_test_setup (allocator , 1024 , & params , s_response , & code );
213- params .vtable .on_code = s_on_code ;
196+ params .vtable .on_response = s_on_response ;
214197 struct aws_http_decoder * decoder = aws_http_decoder_new (& params );
215198
216199 size_t len = strlen (msg );
0 commit comments