1 module soup.Request;
2 
3 private import gio.AsyncResultIF;
4 private import gio.Cancellable;
5 private import gio.InitableIF;
6 private import gio.InitableT;
7 private import gio.InputStream;
8 private import glib.ErrorG;
9 private import glib.GException;
10 private import glib.Str;
11 private import gobject.ObjectG;
12 private import soup.Session;
13 private import soup.URI;
14 private import soup.c.functions;
15 public  import soup.c.types;
16 
17 
18 /**
19  * A #SoupRequest is created by #SoupSession, and represents a request
20  * to retrieve a particular URI.
21  *
22  * Since: 2.42
23  */
24 public class Request : ObjectG, InitableIF
25 {
26 	/** the main Gtk struct */
27 	protected SoupRequest* soupRequest;
28 
29 	/** Get the main Gtk struct */
30 	public SoupRequest* getRequestStruct(bool transferOwnership = false)
31 	{
32 		if (transferOwnership)
33 			ownedRef = false;
34 		return soupRequest;
35 	}
36 
37 	/** the main Gtk struct as a void* */
38 	protected override void* getStruct()
39 	{
40 		return cast(void*)soupRequest;
41 	}
42 
43 	/**
44 	 * Sets our main struct and passes it to the parent class.
45 	 */
46 	public this (SoupRequest* soupRequest, bool ownedRef = false)
47 	{
48 		this.soupRequest = soupRequest;
49 		super(cast(GObject*)soupRequest, ownedRef);
50 	}
51 
52 	// add the Initable capabilities
53 	mixin InitableT!(SoupRequest);
54 
55 
56 	/** */
57 	public static GType getType()
58 	{
59 		return soup_request_get_type();
60 	}
61 
62 	/**
63 	 * Gets the length of the data represented by @request. For most
64 	 * request types, this will not be known until after you call
65 	 * soup_request_send() or soup_request_send_finish().
66 	 *
67 	 * Returns: the length of the data represented by @request,
68 	 *     or -1 if not known.
69 	 *
70 	 * Since: 2.42
71 	 */
72 	public long getContentLength()
73 	{
74 		return soup_request_get_content_length(soupRequest);
75 	}
76 
77 	/**
78 	 * Gets the type of the data represented by @request. For most request
79 	 * types, this will not be known until after you call
80 	 * soup_request_send() or soup_request_send_finish().
81 	 *
82 	 * As in the HTTP Content-Type header, this may include parameters
83 	 * after the MIME type.
84 	 *
85 	 * Returns: the type of the data represented by
86 	 *     @request, or %NULL if not known.
87 	 *
88 	 * Since: 2.42
89 	 */
90 	public string getContentType()
91 	{
92 		return Str.toString(soup_request_get_content_type(soupRequest));
93 	}
94 
95 	/**
96 	 * Gets @request's #SoupSession
97 	 *
98 	 * Returns: @request's #SoupSession
99 	 *
100 	 * Since: 2.42
101 	 */
102 	public Session getSession()
103 	{
104 		auto __p = soup_request_get_session(soupRequest);
105 
106 		if(__p is null)
107 		{
108 			return null;
109 		}
110 
111 		return ObjectG.getDObject!(Session)(cast(SoupSession*) __p);
112 	}
113 
114 	/**
115 	 * Gets @request's URI
116 	 *
117 	 * Returns: @request's URI
118 	 *
119 	 * Since: 2.42
120 	 */
121 	public URI getUri()
122 	{
123 		auto __p = soup_request_get_uri(soupRequest);
124 
125 		if(__p is null)
126 		{
127 			return null;
128 		}
129 
130 		return ObjectG.getDObject!(URI)(cast(SoupURI*) __p);
131 	}
132 
133 	/**
134 	 * Synchronously requests the URI pointed to by @request, and returns
135 	 * a #GInputStream that can be used to read its contents.
136 	 *
137 	 * Note that you cannot use this method with #SoupRequests attached to
138 	 * a #SoupSessionAsync.
139 	 *
140 	 * Params:
141 	 *     cancellable = a #GCancellable or %NULL
142 	 *
143 	 * Returns: a #GInputStream that can be used to
144 	 *     read from the URI pointed to by @request.
145 	 *
146 	 * Since: 2.42
147 	 *
148 	 * Throws: GException on failure.
149 	 */
150 	public InputStream send(Cancellable cancellable)
151 	{
152 		GError* err = null;
153 
154 		auto __p = soup_request_send(soupRequest, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
155 
156 		if (err !is null)
157 		{
158 			throw new GException( new ErrorG(err) );
159 		}
160 
161 		if(__p is null)
162 		{
163 			return null;
164 		}
165 
166 		return ObjectG.getDObject!(InputStream)(cast(GInputStream*) __p, true);
167 	}
168 
169 	/**
170 	 * Begins an asynchronously request for the URI pointed to by
171 	 * @request.
172 	 *
173 	 * Note that you cannot use this method with #SoupRequests attached to
174 	 * a #SoupSessionSync.
175 	 *
176 	 * Params:
177 	 *     cancellable = a #GCancellable or %NULL
178 	 *     callback = a #GAsyncReadyCallback
179 	 *     userData = user data passed to @callback
180 	 *
181 	 * Since: 2.42
182 	 */
183 	public void sendAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
184 	{
185 		soup_request_send_async(soupRequest, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
186 	}
187 
188 	/**
189 	 * Gets the result of a soup_request_send_async().
190 	 *
191 	 * Params:
192 	 *     result = the #GAsyncResult
193 	 *
194 	 * Returns: a #GInputStream that can be used to
195 	 *     read from the URI pointed to by @request.
196 	 *
197 	 * Since: 2.42
198 	 *
199 	 * Throws: GException on failure.
200 	 */
201 	public InputStream sendFinish(AsyncResultIF result)
202 	{
203 		GError* err = null;
204 
205 		auto __p = soup_request_send_finish(soupRequest, (result is null) ? null : result.getAsyncResultStruct(), &err);
206 
207 		if (err !is null)
208 		{
209 			throw new GException( new ErrorG(err) );
210 		}
211 
212 		if(__p is null)
213 		{
214 			return null;
215 		}
216 
217 		return ObjectG.getDObject!(InputStream)(cast(GInputStream*) __p, true);
218 	}
219 }