Skip to content

Commit ebdfbdb

Browse files
committed
Add some pre-conditions.
Part of S507-051.
1 parent e533c32 commit ebdfbdb

8 files changed

+30
-14
lines changed

src/http2/aws-http2-frame-continuation.ads

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ package AWS.HTTP2.Frame.Continuation is
4545
Stream_Id : HTTP2.Stream_Id;
4646
List : Headers.List;
4747
End_Headers : Boolean := True) return Object
48-
with Post => (if End_Headers then Create'Result.Flags = End_Headers_Flag);
48+
with Pre => Stream_Id /= 0,
49+
Post => (if End_Headers then Create'Result.Flags = End_Headers_Flag)
50+
and then Create'Result.Kind = K_Continuation;
51+
-- Create a CONTINUATION frame with given content
4952

5053
overriding procedure Send_Payload
5154
(Self : Object; Sock : Net.Socket_Type'Class);
@@ -56,11 +59,13 @@ package AWS.HTTP2.Frame.Continuation is
5659
-- Iterator interface
5760

5861
function Content_Length
59-
(Self : Object) return Stream_Element_Count;
62+
(Self : Object) return Stream_Element_Count
63+
with Pre => Self.Is_Defined;
6064

6165
function Get
6266
(Self : Object;
63-
Index : Stream_Element_Offset) return Stream_Element;
67+
Index : Stream_Element_Offset) return Stream_Element
68+
with Pre => Self.Is_Defined;
6469

6570
private
6671

src/http2/aws-http2-frame-data.ads

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ package AWS.HTTP2.Frame.Data is
5050
function Create
5151
(Stream_Id : HTTP2.Stream_Id;
5252
Content : String) return Object
53-
with Pre => Stream_Id > 0 and then Content'Length > 0;
53+
with Pre => Stream_Id > 0 and then Content'Length > 0,
54+
Post => Create'Result.Kind = K_Data;
5455
-- Create a DATA frame with given content and stream id
5556

5657
function Create
5758
(Stream_Id : HTTP2.Stream_Id;
5859
Content : Utils.Stream_Element_Array_Access;
5960
End_Stream : Boolean) return Object
60-
with Pre => Stream_Id > 0 and then Content'Length > 0;
61+
with Pre => Stream_Id > 0 and then Content'Length > 0,
62+
Post => Create'Result.Kind = K_Data;
6163
-- Create a DATA frame with given content and stream id
6264

6365
overriding procedure Send_Payload

src/http2/aws-http2-frame-goaway.ads

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ package AWS.HTTP2.Frame.GoAway is
4545

4646
function Create
4747
(Stream_Id : Stream.Id;
48-
Error : Error_Codes) return Object;
48+
Error : Error_Codes) return Object
49+
with Post => Create'Result.Kind = K_GoAway;
4950
-- Create a GOAWAY frame with given content and stream id
5051

5152
function Error (Self : Object) return Error_Codes

src/http2/aws-http2-frame-priority.ads

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ package AWS.HTTP2.Frame.Priority is
4848
(Stream_Id : HTTP2.Stream_Id;
4949
Stream_Dependency : HTTP2.Stream_Id;
5050
Weight : Byte_1) return Object
51-
with Pre => Stream_Id /= Stream_Dependency;
51+
with Pre => Stream_Id /= Stream_Dependency,
52+
Post => Create'Result.Kind = K_Priority;
5253
-- Create a PRIORITY frame (stream id is always 0)
5354

5455
function Read

src/http2/aws-http2-frame-push_promise.ads

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ package AWS.HTTP2.Frame.Push_Promise is
5858
Promise_Stream_Id : HTTP2.Stream_Id;
5959
List : AWS.Headers.List;
6060
End_Headers : Boolean := True) return Object
61-
with Post => (if End_Headers then Create'Result.Flags = End_Headers_Flag);
61+
with Post => (if End_Headers then Create'Result.Flags = End_Headers_Flag)
62+
and then Create'Result.Kind = K_Push_Promise;
6263
-- Create an HEADERS frame with given content and stream id
6364

6465
function Get
6566
(Self : Object;
6667
Table : not null access HTTP2.HPACK.Table.Object;
6768
Settings : not null access HTTP2.Connection.Object)
68-
return AWS.Headers.List;
69+
return AWS.Headers.List
70+
with Pre => Self.Is_Defined;
6971
-- Get the header list out of the HEADERS frame. This reads the content of
7072
-- the payload and decode using HPACK.
7173

src/http2/aws-http2-frame-rst_stream.ads

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ package AWS.HTTP2.Frame.RST_Stream is
4747

4848
function Create
4949
(Error : Error_Codes;
50-
Stream_Id : Stream.Id) return Object;
51-
-- Create an RST_Stream frame (stream id is 0)
50+
Stream_Id : Stream.Id) return Object
51+
with Pre => Stream_Id /= 0,
52+
Post => Create'Result.Kind = K_RST_Stream;
53+
-- Create an RST_Stream frame
5254

5355
overriding procedure Send_Payload
5456
(Self : Object; Sock : Net.Socket_Type'Class)

src/http2/aws-http2-frame.ads

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ package AWS.HTTP2.Frame is
124124
(Self : Object'Class;
125125
Settings : Connection.Object;
126126
Error : out Error_Codes) return Boolean
127-
with Pre => Self.Is_Defined;
127+
with Pre => Self.Is_Defined,
128+
Post => Is_Valid'Result = (Error = C_No_Error);
128129
-- Set Error to appropriate value with Validate routine and return True if
129130
-- Error became C_No_Error, returns False otherwise.
130131

src/http2/aws-http2.ads

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ package AWS.HTTP2 is
6262
-- "PRI * HTTP/2.0" & CRLF & CRLF & "SM" & CRLF & CRLF
6363

6464
function Exception_Message
65-
(Error : Error_Codes; Message : String) return String;
65+
(Error : Error_Codes; Message : String) return String
66+
with Pre => Message /= "";
6667
-- Build an exception message with the error code endoded at the start of
6768
-- the message and surrounded with square brackets.
6869

69-
function Exception_Code (Exception_Message : String) return Error_Codes;
70+
function Exception_Code (Exception_Message : String) return Error_Codes
71+
with Pre => Exception_Message'Length > 2;
7072
-- Extract the execption code from an exception message built with the
7173
-- Exception_Message routine above.
7274

0 commit comments

Comments
 (0)