@@ -3,52 +3,44 @@ extern "C" {
33#include " quic.h"
44}
55
6+ #include " Http3ContextData.h"
7+ #include " Http3ResponseData.h"
68
79/* Let's just have this one here for now */
810us_quic_socket_context_t *context;
911
10- void print_current_headers () {
11- /* Iterate the headers and print them */
12- for (int i = 0 , more = 1 ; more; i++) {
13- char *name, *value;
14- int name_length, value_length;
15- if (more = us_quic_socket_context_get_header (context, i, &name, &name_length, &value, &value_length)) {
16- printf (" header %.*s = %.*s\n " , name_length, name, value_length, value);
17- }
18- }
19- }
20-
2112/* This would be a request */
2213void on_stream_headers (us_quic_stream_t *s) {
2314
24- printf ( " ==== HTTP/3 request ==== \n " );
15+ Http3ContextData *contextData = (Http3ContextData *) us_quic_socket_context_ext ( us_quic_socket_context ( us_quic_stream_socket (s)) );
2516
26- print_current_headers ();
17+ contextData-> router . route ();
2718
28- /* Write headers */
29- us_quic_socket_context_set_header (context, 0 , " :status" , 7 , " 200" , 3 );
30- // us_quic_socket_context_set_header(context, 1, "content-length", 14, "11", 2);
31- // us_quic_socket_context_set_header(context, 2, "content-type", 12, "text/html", 9);
32- us_quic_socket_context_send_headers (context, s, 1 , 1 );
3319
34- /* Write body and shutdown (unknown if content-length must be present?) */
35- us_quic_stream_write (s, " Hello quic!" , 11 );
36-
37- /* Every request has its own stream, so we conceptually serve requests like in HTTP 1.0 */
38- us_quic_stream_shutdown (s);
3920}
4021
4122/* And this would be the body of the request */
4223void on_stream_data (us_quic_stream_t *s, char *data, int length) {
24+
25+ // Http3ResponseData *responseData = us_quic_stream_ext(s);
26+ // responseData->onData(data, length);
27+
4328 printf (" Body length is: %d\n " , length);
4429}
4530
4631void on_stream_writable (us_quic_stream_t *s) {
47-
32+ // Http3ResponseData *responseData = us_quic_stream_ext(s);
33+ // responseData->onWritable();
4834}
4935
5036void on_stream_close (us_quic_stream_t *s) {
51- printf (" Stream closed\n " );
37+
38+ // Http3ResponseData *responseData = us_quic_stream_ext(s);
39+ // responseData->onAborted();
40+
41+ // printf("Stream closed\n");
42+
43+ // inplace destruct Http3ResponseData here
5244}
5345
5446/* On new connection */
@@ -58,7 +50,9 @@ void on_open(us_quic_socket_t *s, int is_client) {
5850
5951/* On new stream */
6052void on_stream_open (us_quic_stream_t *s, int is_client) {
61- printf (" Stream opened!\n " );
53+ // printf("Stream opened!\n");
54+
55+ // inplace initialize Http3ResponseData here
6256}
6357
6458void on_close (us_quic_socket_t *s) {
@@ -73,7 +67,7 @@ namespace uWS {
7367 printf (" Creating context now\n " );
7468
7569 /* Create quic socket context (assumes h3 for now) */
76- context = us_create_quic_socket_context (loop, options);
70+ context = us_create_quic_socket_context (loop, options); // sizeof(Http3ContextData)
7771
7872 /* Specify application callbacks */
7973 us_quic_socket_context_on_stream_data (context, on_stream_data);
@@ -85,7 +79,7 @@ namespace uWS {
8579 us_quic_socket_context_on_close (context, on_close);
8680
8781 /* The listening socket is the actual UDP socket used */
88- us_quic_listen_socket_t *listen_socket = us_quic_socket_context_listen (context, " ::1" , 9004 );
82+ us_quic_listen_socket_t *listen_socket = us_quic_socket_context_listen (context, " ::1" , 9004 ); // sizeof(Http3ResponseData)
8983
9084
9185 return nullptr ;
0 commit comments