Skip to content

Commit 243bc2b

Browse files
committed
First implementation of the client GET/POST methods with HTTP/2.
Add corresponding regression test. Part of S507-051.
1 parent 5fafdbf commit 243bc2b

File tree

12 files changed

+678
-118
lines changed

12 files changed

+678
-118
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
------------------------------------------------------------------------------
2+
-- Ada Web Server --
3+
-- --
4+
-- Copyright (C) 2021, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it --
7+
-- under terms of the GNU General Public License as published by the --
8+
-- Free Software Foundation; either version 3, or (at your option) any --
9+
-- later version. This software is distributed in the hope that it will --
10+
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
11+
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
12+
-- General Public License for more details. --
13+
-- --
14+
-- You should have received a copy of the GNU General Public License --
15+
-- distributed with this software; see file COPYING3. If not, go --
16+
-- to http://www.gnu.org/licenses for a complete copy of the license. --
17+
------------------------------------------------------------------------------
18+
19+
with Ada.Strings.Unbounded;
20+
with Ada.Text_IO;
21+
22+
with AWS.Client;
23+
with AWS.Config.Set;
24+
with AWS.MIME;
25+
with AWS.Response;
26+
with AWS.Server.Log;
27+
with AWS.Server.Status;
28+
with AWS.Status;
29+
with AWS.Utils;
30+
31+
procedure H2_Hello is
32+
33+
use Ada.Strings.Unbounded;
34+
use AWS;
35+
36+
WS : Server.HTTP;
37+
38+
function CB (Request : Status.Data) return Response.Data is
39+
Mes : constant Unbounded_String := Status.Binary_Data (Request);
40+
begin
41+
if Length (Mes) /= 0 then
42+
return Response.Build
43+
(MIME.Text_HTML, "Hello World to H2! (" & To_String (Mes) & ')');
44+
else
45+
return Response.Build (MIME.Text_HTML, "Hello World to H2!");
46+
end if;
47+
end CB;
48+
49+
Conf : Config.Object := Config.Get_Current;
50+
R : Response.Data;
51+
52+
begin
53+
Config.Set.Server_Name (Conf, "HTTP/2 Server");
54+
Config.Set.Server_Port (Conf, 0);
55+
Config.Set.Max_Connection (Conf, 5);
56+
Config.Set.HTTP2_Activated (Conf, True);
57+
58+
AWS.Server.Log.Start_Error (WS);
59+
60+
Server.Start (WS, CB'Unrestricted_Access, Conf);
61+
Ada.Text_IO.Put_Line ("started"); Ada.Text_IO.Flush;
62+
63+
delay 1.0;
64+
65+
R := Client.Get (Server.Status.Local_URL (WS),
66+
HTTP_Version => HTTPv2);
67+
Ada.Text_IO.Put_Line ("R-GET : " & Response.Message_Body (R));
68+
69+
R := Client.Post (Server.Status.Local_URL (WS),
70+
Data => "Some text as message",
71+
HTTP_Version => HTTPv2);
72+
Ada.Text_IO.Put_Line ("R-POST : " & Response.Message_Body (R));
73+
74+
Server.Shutdown (WS);
75+
Ada.Text_IO.Put_Line ("shutdown");
76+
end H2_Hello;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
------------------------------------------------------------------------------
2+
-- Ada Web Server --
3+
-- --
4+
-- Copyright (C) 2021, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it --
7+
-- under terms of the GNU General Public License as published by the --
8+
-- Free Software Foundation; either version 3, or (at your option) any --
9+
-- later version. This software is distributed in the hope that it will --
10+
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
11+
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
12+
-- General Public License for more details. --
13+
-- --
14+
-- You should have received a copy of the GNU General Public License --
15+
-- distributed with this software; see file COPYING3. If not, go --
16+
-- to http://www.gnu.org/licenses for a complete copy of the license. --
17+
------------------------------------------------------------------------------
18+
19+
with "aws";
20+
21+
project H2_Hello is
22+
for Source_Dirs use (".", "../common");
23+
for Main use ("h2_hello.adb");
24+
end H2_Hello;

regtests/0344_http2_hello/test.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
started
2+
R-GET : Hello World to H2!
3+
R-POST : Hello World to H2! (Some text as message)
4+
shutdown

regtests/0344_http2_hello/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from test_support import *
2+
3+
build_and_run('h2_hello');

0 commit comments

Comments
 (0)