|
| 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; |
0 commit comments