/[eiffelstudio]/branches/eth/eve/Src/contrib/library/network/http_client/src/http_client_session.e
ViewVC logotype

Contents of /branches/eth/eve/Src/contrib/library/network/http_client/src/http_client_session.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 92964 - (show annotations)
Fri Sep 20 05:41:23 2013 UTC (6 years ago) by jasonw
File size: 7339 byte(s)
<<Merged from trunk#92963.>>
1 note
2 description : "[
3 HTTP_CLIENT_SESSION represents a session
4 and is used to call get, post, .... request
5 with predefined settings such as
6 base_url
7 specific common headers
8 timeout and so on ...
9 ]"
10 date: "$Date$"
11 revision: "$Revision$"
12
13 deferred class
14 HTTP_CLIENT_SESSION
15
16 inherit
17 ANY
18
19 HTTP_CLIENT_CONSTANTS
20 rename
21 auth_type_id as auth_type_id_from_string
22 export
23 {NONE} all
24 end
25
26 feature {NONE} -- Initialization
27
28 make (a_base_url: READABLE_STRING_8)
29 -- Initialize `Current'.
30 do
31 set_defaults
32 create headers.make (3)
33
34 base_url := a_base_url
35 initialize
36 end
37
38 set_defaults
39 do
40 timeout := 5
41 connect_timeout := 1
42 max_redirects := 5
43 set_basic_auth_type
44 end
45
46 initialize
47 deferred
48 end
49
50 feature -- Basic operation
51
52 url (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): STRING_8
53 -- Url computed from Current and `ctx' data.
54 local
55 s: STRING_8
56 url_encoder: URL_ENCODER
57 do
58 Result := base_url + a_path
59 if ctx /= Void then
60 create s.make_empty
61 create url_encoder
62 across
63 ctx.query_parameters as q
64 loop
65 if not s.is_empty then
66 s.append_character ('&')
67 end
68 s.append (url_encoder.encoded_string (q.key))
69 s.append_character ('=')
70 s.append (url_encoder.encoded_string (q.item))
71 end
72 if not s.is_empty then
73 Result.append_character ('?')
74 Result.append (s)
75 end
76 end
77 end
78
79 feature -- Custom
80
81 custom (a_method: READABLE_STRING_8; a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
82 -- Response for `a_method' request based on Current, `a_path' and `ctx'.
83 deferred
84 end
85
86 feature -- Helper
87
88 get (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
89 -- Response for GET request based on Current, `a_path' and `ctx'.
90 deferred
91 end
92
93 head (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
94 -- Response for HEAD request based on Current, `a_path' and `ctx'.
95 deferred
96 end
97
98 post (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
99 -- Response for POST request based on Current, `a_path' and `ctx'
100 -- with input `data'
101 deferred
102 end
103
104 post_file (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
105 -- Response for POST request based on Current, `a_path' and `ctx'
106 -- with uploaded data file `fn'
107 deferred
108 end
109
110 patch (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
111 -- Response for PATCH request based on Current, `a_path' and `ctx'
112 -- with input `data'
113 deferred
114 end
115
116 patch_file (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
117 -- Response for PATCH request based on Current, `a_path' and `ctx'
118 -- with uploaded data file `fn'
119 deferred
120 end
121
122 put (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
123 -- Response for PUT request based on Current, `a_path' and `ctx'
124 -- with input `data'
125 deferred
126 end
127
128 put_file (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
129 -- Response for PUT request based on Current, `a_path' and `ctx'
130 -- with uploaded file `fn'
131 deferred
132 end
133
134 delete (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
135 -- Response for DELETE request based on Current, `a_path' and `ctx'
136 deferred
137 end
138
139 feature -- Status report
140
141 is_debug: BOOLEAN
142 -- Produce debug output
143
144 is_available: BOOLEAN
145 -- Is interface usable?
146 deferred
147 end
148
149 feature -- Settings
150
151 timeout: INTEGER
152 -- HTTP transaction timeout in seconds. Defaults to 5 seconds.
153
154 connect_timeout: INTEGER
155 -- HTTP connection timeout in seconds. Defaults to 1 second.
156
157 max_redirects: INTEGER
158 -- Maximum number of times to follow redirects.
159 -- Set to 0 to disable and -1 to follow all redirects. Defaults to 5.
160
161 ignore_content_length: BOOLEAN
162 -- Does this session ignore Content-Size headers?
163
164 buffer_size: NATURAL
165 -- Set the buffer size for request. This option will
166 -- only be set if buffer_size is positive
167
168 default_response_charset: detachable READABLE_STRING_8
169 -- Default encoding of responses. Used if no charset is provided by the host.
170
171 is_insecure: BOOLEAN
172 -- Allow connections to SSL sites without certs
173
174 proxy: detachable TUPLE [host: READABLE_STRING_8; port: INTEGER]
175 -- Proxy information [`host' and `port']
176
177 feature -- Access
178
179 base_url: READABLE_STRING_8
180 -- Base URL for any request created by Current session.
181
182 headers: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
183 -- Headers common to any request created by Current session.
184
185 feature -- Authentication
186
187 auth_type: STRING
188 -- Set the authentication type for the request.
189 -- Types: "basic", "digest", "any"
190
191 auth_type_id: INTEGER
192 -- See {HTTP_CLIENT_CONSTANTS}.Auth_type_*
193
194 username,
195 password: detachable READABLE_STRING_32
196
197 credentials: detachable READABLE_STRING_32
198
199
200 feature -- Status setting
201
202 set_is_debug (b: BOOLEAN)
203 do
204 is_debug := b
205 end
206
207 feature -- Element change
208
209 set_base_url (u: like base_url)
210 do
211 base_url := u
212 end
213
214 set_timeout (n_seconds: like timeout)
215 do
216 timeout := n_seconds
217 end
218
219 set_connect_timeout (n: like connect_timeout)
220 do
221 connect_timeout := n
222 end
223
224 set_user_agent (v: READABLE_STRING_8)
225 do
226 add_header ("User-Agent", v)
227 end
228
229 set_is_insecure (b: BOOLEAN)
230 do
231 is_insecure := b
232 end
233
234 add_header (k: READABLE_STRING_8; v: READABLE_STRING_8)
235 do
236 headers.force (v, k)
237 end
238
239 remove_header (k: READABLE_STRING_8)
240 do
241 headers.prune (k)
242 end
243
244 set_credentials (u: like username; p: like password)
245 do
246 username := u
247 password := p
248 if u /= Void and p /= Void then
249 credentials := u + ":" + p
250 else
251 credentials := Void
252 end
253 end
254
255 set_auth_type (s: READABLE_STRING_8)
256 do
257 auth_type := s
258 auth_type_id := auth_type_id_from_string (s)
259 end
260
261 set_basic_auth_type
262 do
263 auth_type := "basic"
264 auth_type_id := Auth_type_basic
265 end
266
267 set_digest_auth_type
268 do
269 auth_type := "digest"
270 auth_type_id := Auth_type_digest
271 end
272
273 set_any_auth_type
274 do
275 auth_type := "any"
276 auth_type_id := Auth_type_any
277 end
278
279 set_anysafe_auth_type
280 do
281 auth_type := "anysafe"
282 auth_type_id := Auth_type_anysafe
283 end
284
285 set_max_redirects (n: like max_redirects)
286 do
287 max_redirects := n
288 end
289
290 set_proxy (a_host: detachable READABLE_STRING_8; a_port: INTEGER)
291 do
292 if a_host = Void then
293 proxy := Void
294 else
295 proxy := [a_host, a_port]
296 end
297 end
298
299 note
300 copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
301 license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
302 source: "[
303 Eiffel Software
304 5949 Hollister Ave., Goleta, CA 93117 USA
305 Telephone 805-685-1006, Fax 805-685-6869
306 Website http://www.eiffel.com
307 Customer support http://support.eiffel.com
308 ]"
309 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23