219 if (d->m_jobId)
220 removeFromOutstandingJobs(d->m_jobId);
221 }
222
223 void ResourceHandle::onHandleCreated(LPARAM lParam)
224 {
225 if (!d->m_resourceHandle) {
226 d->m_resourceHandle = HINTERNET(lParam);
227 if (d->status != 0) {
228 // We were canceled before Windows actually created a handle for us, close and delete now.
229 InternetCloseHandle(d->m_resourceHandle);
230 delete this;
231 return;
232 }
233
234 if (request().httpMethod() == "POST") {
235 // FIXME: Too late to set referrer properly.
236 String urlStr = request().url().path();
237 int fragmentIndex = urlStr.find('#');
238 if (fragmentIndex != -1)
239 urlStr = urlStr.left(fragmentIndex);
240 static LPCSTR accept[2]={"*/*", NULL};
241 HINTERNET urlHandle = HttpOpenRequestA(d->m_resourceHandle,
242 "POST", urlStr.latin1().data(), 0, 0, accept,
243 INTERNET_FLAG_KEEP_CONNECTION |
244 INTERNET_FLAG_FORMS_SUBMIT |
245 INTERNET_FLAG_RELOAD |
246 INTERNET_FLAG_NO_CACHE_WRITE |
247 INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
248 INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP,
249 (DWORD_PTR)d->m_jobId);
250 if (urlHandle == INVALID_HANDLE_VALUE) {
251 InternetCloseHandle(d->m_resourceHandle);
252 delete this;
253 }
254 }
255 } else if (!d->m_secondaryHandle) {
256 assert(request().httpMethod() == "POST");
257 d->m_secondaryHandle = HINTERNET(lParam);
258
259 // Need to actually send the request now.
260 String headers = "Content-Type: application/x-www-form-urlencoded\n";
261 headers += "Referer: ";
262 headers += d->m_postReferrer;
263 headers += "\n";
264 const CString& headersLatin1 = headers.latin1();
265 if (firstRequest().httpBody()) {
266 firstRequest().httpBody()->flatten(d->m_formData);
267 d->m_bytesRemainingToWrite = d->m_formData.size();
268 }
269 INTERNET_BUFFERSA buffers;
270 memset(&buffers, 0, sizeof(buffers));
271 buffers.dwStructSize = sizeof(INTERNET_BUFFERSA);
272 buffers.lpcszHeader = headersLatin1.data();
273 buffers.dwHeadersLength = headers.length();
274 buffers.dwBufferTotal = d->m_bytesRemainingToWrite;
275
276 HttpSendRequestExA(d->m_secondaryHandle, &buffers, 0, 0, (DWORD_PTR)d->m_jobId);
277 // FIXME: add proper error handling
278 }