Skip to content

Commit

Permalink
Merge branch 'po/client-http2'
Browse files Browse the repository at this point in the history
* po/client-http2: (51 commits)
  Simplify code by using To_Lower as in pure HTTP/2 unit.
  Ensure we handle possible corruped data/frames.
  Add some pre-conditions.
  Minor code clean-up.
  Properly initialize the connection object based on settings.
  Clean-up multiple definitions of CRLF.
  Minor code reformatting and clean-up.
  Code refactoring, better sharing.
  Rework the handling of headers for HTTP/2 responses.
  Send_Request_2: Rewrite to properly handle large request & response.
  Read_Body is only to be used with HTTP/1.x.
  Fix POST support, nothing to do if the body is empty.
  New routine HTTP_Version to get the connection's protocol version.
  Add new routine to directly set the headers list.
  Fix implementation of POST without attachment.
  Refactor code for sharing.
  Add initial support for POST with attachments for HTTP/2.
  Properly update connection flow control window.
  Fix wrong initialization of Max_Frame_Size (cut&paste) error.
  Use a unique port for 0345_http2_soap_hello.
  ...
  • Loading branch information
TurboGit committed Oct 6, 2021
2 parents 70133fe + 36373d7 commit e00b68a
Show file tree
Hide file tree
Showing 69 changed files with 2,908 additions and 816 deletions.
8 changes: 6 additions & 2 deletions regtests/0341_hpack/main.adb
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,18 @@ procedure Main is
end loop;
end Print;

M : AWS.Headers.List := Decode (Tab_Dec'Access, Settings'Access);
M : constant AWS.Headers.List :=
Decode (Tab_Dec'Access, Settings'Access);

use type AWS.Headers.List;
use type AWS.HTTP2.HPACK.Table.Object;

begin
if M /= H then
Ada.Text_IO.Put_Line ("Headers differ");
Ada.Text_IO.Put_Line ("============= Headers differ");
Print (H);
Print (M);
New_Line;
end if;

if Tab_Enc /= Tab_Dec then
Expand All @@ -100,6 +102,8 @@ procedure Main is
Size : Positive;

begin
H.Case_Sensitive (False);

H.Add (":method", "GET");
H.Add (":path", "/readme.txt");
H.Add (":scheme", "https");
Expand Down
1 change: 1 addition & 0 deletions regtests/0345_http2_soap_hello/test.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!xmlada DEAD
1 change: 1 addition & 0 deletions regtests/0345_http2_soap_hello/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello AWS and welcome in H2! 12
4 changes: 4 additions & 0 deletions regtests/0345_http2_soap_hello/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from test_support import *

exec_cmd('wsdl2aws', ['-q', '-f', '-doc', 'wsdl_h2hello.wsdl'])
build_and_run('wsdl_h2hello')
116 changes: 116 additions & 0 deletions regtests/0345_http2_soap_hello/wsdl_h2hello.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2021, AdaCore --
-- --
-- This is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 3, or (at your option) any --
-- later version. This software is distributed in the hope that it will --
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- distributed with this software; see file COPYING3. If not, go --
-- to http://www.gnu.org/licenses for a complete copy of the license. --
------------------------------------------------------------------------------

-- SOAP/WSDL test

with Ada.Strings.Unbounded;
with Ada.Text_IO;

with AWS.Config.Set;
with AWS.MIME;
with AWS.Net;
with AWS.Response;
with AWS.Server.Status;
with AWS.Status;

with SOAP.Types;
with SOAP.Utils;

with R_Hello_Demo.Client;
with R_Hello_Demo.Server;
with R_Hello_Demo.Types;

procedure WSDL_H2Hello is

use Ada.Strings.Unbounded;
use AWS;
use R_Hello_Demo.Types;

H_Server : Server.HTTP;
CNF : Config.Object;

procedure WSDL_Demo_Client is
use Ada;
R : Sayhello_Result;
begin
R := R_Hello_Demo.Client.sayHello (Firstname => "AWS");
Text_IO.Put_Line
(To_String (R.Message) & SOAP.Types.Short'Image (R.Token));
end WSDL_Demo_Client;

function sayHello (Firstname : String) return Sayhello_Result;

-------------
-- SOAP_CB --
-------------

function SOAP_CB is new R_Hello_Demo.Server.sayHello_CB (sayHello);

function SOAP_Wrapper is new SOAP.Utils.SOAP_Wrapper (SOAP_CB);

--------
-- CB --
--------

function CB (Request : Status.Data) return Response.Data is
SOAPAction : constant String := Status.SOAPAction (Request);
begin
if SOAPAction = "sayHello" then
return SOAP_Wrapper (Request);
else
return Response.Build (MIME.Text_HTML, "<p>Not a SOAP request");
end if;
end CB;

--------------
-- sayHello --
--------------

function sayHello (Firstname : String) return Sayhello_Result is
begin
return
(To_Unbounded_String
("Hello " & Firstname & " and welcome in H2!"), 12);
end sayHello;

begin
Config.Set.Server_Name (CNF, "WSDL Hello demo");
Config.Set.Server_Host (CNF, "localhost");
Config.Set.Server_Port (CNF, R_Hello_Demo.Server.Port);
Config.Set.HTTP2_Activated (CNF, True);

Server.Start (H_Server, CB'Unrestricted_Access, CNF);

if Net.IPv6_Available then
-- Need to start second server on same port but on the different
-- Protocol_Family because we do not know which family would client try
-- to connect.

if AWS.Server.Status.Is_IPv6 (H_Server) then
Server.Add_Listening
(H_Server, "localhost", R_Hello_Demo.Server.Port, Net.FAMILY_INET);
else
Server.Add_Listening
(H_Server, "localhost", R_Hello_Demo.Server.Port, Net.FAMILY_INET6);
end if;
end if;

WSDL_Demo_Client;

Server.Shutdown (H_Server);
end WSDL_H2Hello;
24 changes: 24 additions & 0 deletions regtests/0345_http2_soap_hello/wsdl_h2hello.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2021, AdaCore --
-- --
-- This is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 3, or (at your option) any --
-- later version. This software is distributed in the hope that it will --
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- distributed with this software; see file COPYING3. If not, go --
-- to http://www.gnu.org/licenses for a complete copy of the license. --
------------------------------------------------------------------------------

with "aws";

project WSDL_H2Hello is
for Source_Dirs use (".");
for Main use ("wsdl_h2hello.adb");
end WSDL_H2Hello;
131 changes: 131 additions & 0 deletions regtests/0345_http2_soap_hello/wsdl_h2hello.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="HelloService"
targetNamespace="http://www.s.com/wsdl/hs.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.s.com/wsdl/hs.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="urn:examples:helloservice">

<types>
<schema>
<complexType name="ArrayOffloat">
<xsd:annotation>
<xsd:documentation>
A set of float
</xsd:documentation>
</xsd:annotation>
<complexContent>
<restriction base="soap-enc:Array">
<attribute ref="soap-enc:arrayType" arrayType="xsd:float[]"/>
</restriction>
</complexContent>
</complexType>

<xsd:complexType name="HelloResponse">
<xsd:annotation>
<xsd:documentation>
A message/token pair
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="message" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
The reponse string.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="token" type="xsd:short">
<xsd:annotation>
<xsd:documentation>
Value representing the length of the response.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</schema>
</types>

<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="HelloResponse"/>
</message>

<message name="CallRequest">
<part name="firstName" type="ArrayOffloat"/>
</message>
<message name="CallResponse">
<part name="greeting" type="xsd:int"/>
</message>

<portType name="Hello_PortType">
<documentation>
This web service provides a simple Hello World.
</documentation>
<operation name="sayHello">
<documentation>
Called with a firstName, and returns a greeting message.
This is very simple SOAP callback. The input message is a simple string,
the response is a complexType with the response and a uniq token value.
</documentation>
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
<operation name="call">
<documentation>
just for the documentation validation.
</documentation>
<input message="tns:CallRequest"/>
<output message="tns:CallResponse"/>
</operation>
</portType>

<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</output>
</operation>
<operation name="call">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</output>
</operation>
</binding>

<service name="R_Hello_Demo">
<documentation>
WSDL File for Hello AWS Demo.
</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address
location="http://localhost:9837/hello"/>
</port>
</service>
</definitions>
1 change: 1 addition & 0 deletions regtests/0346_http2_post_attachments/file1.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file1
1 change: 1 addition & 0 deletions regtests/0346_http2_post_attachments/file2.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file2
Loading

0 comments on commit e00b68a

Please sign in to comment.