1----------------------------------------------------------------------- 2-- util-http-clients-web -- HTTP Clients with AWS implementation 3-- Copyright (C) 2011, 2012 Stephane Carrez 4-- Written by Stephane Carrez (Stephane.Carrez@gmail.com) 5-- 6-- Licensed under the Apache License, Version 2.0 (the "License"); 7-- you may not use this file except in compliance with the License. 8-- You may obtain a copy of the License at 9-- 10-- http://www.apache.org/licenses/LICENSE-2.0 11-- 12-- Unless required by applicable law or agreed to in writing, software 13-- distributed under the License is distributed on an "AS IS" BASIS, 14-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15-- See the License for the specific language governing permissions and 16-- limitations under the License. 17----------------------------------------------------------------------- 18 19private with AWS.Headers; 20private with AWS.Response; 21package Util.Http.Clients.Web is 22 23 -- Register the Http manager. 24 procedure Register; 25 26private 27 28 type AWS_Http_Manager is new Http_Manager with null record; 29 type AWS_Http_Manager_Access is access all Http_Manager'Class; 30 31 procedure Create (Manager : in AWS_Http_Manager; 32 Http : in out Client'Class); 33 34 procedure Do_Get (Manager : in AWS_Http_Manager; 35 Http : in Client'Class; 36 URI : in String; 37 Reply : out Response'Class); 38 39 procedure Do_Post (Manager : in AWS_Http_Manager; 40 Http : in Client'Class; 41 URI : in String; 42 Data : in String; 43 Reply : out Response'Class); 44 45 type AWS_Http_Request is new Http_Request with record 46 Headers : AWS.Headers.List; 47 end record; 48 type AWS_Http_Request_Access is access all AWS_Http_Request'Class; 49 50 -- Returns a boolean indicating whether the named request header has already 51 -- been set. 52 overriding 53 function Contains_Header (Http : in AWS_Http_Request; 54 Name : in String) return Boolean; 55 56 -- Returns the value of the specified request header as a String. If the request 57 -- did not include a header of the specified name, this method returns null. 58 -- If there are multiple headers with the same name, this method returns the 59 -- first head in the request. The header name is case insensitive. You can use 60 -- this method with any response header. 61 overriding 62 function Get_Header (Request : in AWS_Http_Request; 63 Name : in String) return String; 64 65 -- Sets a request header with the given name and value. If the header had already 66 -- been set, the new value overwrites the previous one. The containsHeader 67 -- method can be used to test for the presence of a header before setting its value. 68 overriding 69 procedure Set_Header (Http : in out AWS_Http_Request; 70 Name : in String; 71 Value : in String); 72 73 -- Adds a request header with the given name and value. 74 -- This method allows request headers to have multiple values. 75 overriding 76 procedure Add_Header (Http : in out AWS_Http_Request; 77 Name : in String; 78 Value : in String); 79 80 -- Iterate over the request headers and executes the <b>Process</b> procedure. 81 overriding 82 procedure Iterate_Headers (Request : in AWS_Http_Request; 83 Process : not null access 84 procedure (Name : in String; 85 Value : in String)); 86 87 type AWS_Http_Response is new Http_Response with record 88 Data : AWS.Response.Data; 89 end record; 90 type AWS_Http_Response_Access is access all AWS_Http_Response'Class; 91 92 -- Returns a boolean indicating whether the named response header has already 93 -- been set. 94 overriding 95 function Contains_Header (Reply : in AWS_Http_Response; 96 Name : in String) return Boolean; 97 98 -- Returns the value of the specified response header as a String. If the response 99 -- did not include a header of the specified name, this method returns null. 100 -- If there are multiple headers with the same name, this method returns the 101 -- first head in the request. The header name is case insensitive. You can use 102 -- this method with any response header. 103 overriding 104 function Get_Header (Reply : in AWS_Http_Response; 105 Name : in String) return String; 106 107 -- Sets a message header with the given name and value. If the header had already 108 -- been set, the new value overwrites the previous one. The containsHeader 109 -- method can be used to test for the presence of a header before setting its value. 110 overriding 111 procedure Set_Header (Reply : in out AWS_Http_Response; 112 Name : in String; 113 Value : in String); 114 115 -- Adds a request header with the given name and value. 116 -- This method allows request headers to have multiple values. 117 overriding 118 procedure Add_Header (Reply : in out AWS_Http_Response; 119 Name : in String; 120 Value : in String); 121 122 -- Iterate over the response headers and executes the <b>Process</b> procedure. 123 overriding 124 procedure Iterate_Headers (Reply : in AWS_Http_Response; 125 Process : not null access 126 procedure (Name : in String; 127 Value : in String)); 128 129 -- Get the response body as a string. 130 function Get_Body (Reply : in AWS_Http_Response) return String; 131 132 -- Get the response status code. 133 overriding 134 function Get_Status (Reply : in AWS_Http_Response) return Natural; 135 136end Util.Http.Clients.Web; 137