Skip to content

Instantly share code, notes, and snippets.

@overcq
Last active October 22, 2022 07:01
Show Gist options
  • Save overcq/9e851233d5692a4973caa9a584de7680 to your computer and use it in GitHub Desktop.
Save overcq/9e851233d5692a4973caa9a584de7680 to your computer and use it in GitHub Desktop.
Simple HTTP/1.1 and HTTP/2 client in OUX/C+
//-*-C-*-
N E_main_Q_http_req_ret_count;
void
http_req_ret_func( N connection_i
){ E_main_Q_http_req_ret_count++;
V0( unlink( E_net_http_S_connect[ connection_i ].file_name ) ){}
E_net_http_S_connect[ connection_i ].ret_func = 0;
}
void
http2_req_ret_func( N connection_i
, I stream_id
){ E_main_Q_http_req_ret_count++;
struct E_net_http2_Z_stream *stream = E_mem_Q_tab_R( E_net_http2_S_connect[ connection_i ].stream, stream_id );
V0( unlink( stream->file_name ) ){}
}
SSL_CTX *ssl_ctx = E_net_cli_Q_ssl_M();
if( !ssl_ctx )
goto End; // Nie udało się utworzyć kontekstu SSL.
B http2;
N connection = E_net_cli_Q_ssl_I_connect( ssl_ctx, "gentoo", &http2 );
if( !~connection )
goto Skip; // Nie udało się utworzyć połączenia.
if(http2)
{ N ret = E_net_http2_I_request( connection, "/", http2_req_ret_func );
if(ret)
goto Skip; // Nie udało się wysłać ścieżki żądania.
ret = E_net_http2_I_request( connection, "/", http2_req_ret_func );
if(ret)
goto Skip; // Nie udało się wysłać ścieżki żądania.
}else
{ N ret = E_net_http_I_request( connection, "/", http_req_ret_func );
if(ret)
goto Skip; // Nie udało się wysłać ścieżki żądania.
}
X_M( net, ret );
E_main_Q_http_req_ret_count = 0;
O{ X_B( net, ret, 0 )
break;
if(( http2
&& ( !E_net_http2_S_connect_n
|| E_main_Q_http_req_ret_count == 2 // Zrealizowano dwa połączenia HTTP/2.
))
|| ( !http2
&& ( !E_net_http_S_connect_n
|| E_main_Q_http_req_ret_count == 1 // Zrealizowano jedno połączenie HTTP/1.1.
)))
break;
}
Skip:
E_net_cli_Q_ssl_W( ssl_ctx );
End:;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment