65 { |
64 { |
66 // HTTP response headers have been received. We can determine now if there is |
65 // HTTP response headers have been received. We can determine now if there is |
67 // going to be a response body to save. |
66 // going to be a response body to save. |
68 RHTTPResponse resp = aTransaction.Response(); |
67 RHTTPResponse resp = aTransaction.Response(); |
69 iLastStatusCode = resp.StatusCode(); |
68 iLastStatusCode = resp.StatusCode(); |
70 RStringF statusStr = resp.StatusText(); |
69 DP1("Status: %d", iLastStatusCode); |
71 TBuf<32> statusStr16; |
|
72 statusStr16.Copy(statusStr.DesC()); |
|
73 DP2("Status: %d (%S)", iLastStatusCode, &statusStr16); |
|
74 |
70 |
75 // Dump the headers if we're being verbose |
71 // Dump the headers if we're being verbose |
76 //DumpRespHeadersL(aTransaction); |
72 //DumpRespHeadersL(aTransaction); |
77 |
73 |
78 // Determine if the body will be saved to disk |
74 // Determine if the body will be saved to disk |
103 } |
99 } |
104 else if (iSavingResponseBody) // If we're saving, then open a file handle for the new file |
100 else if (iSavingResponseBody) // If we're saving, then open a file handle for the new file |
105 { |
101 { |
106 iFileServ.Parse(iFileName, iParsedFileName); |
102 iFileServ.Parse(iFileName, iParsedFileName); |
107 TInt valid = iFileServ.IsValidName(iFileName); |
103 TInt valid = iFileServ.IsValidName(iFileName); |
|
104 |
108 if (!valid) |
105 if (!valid) |
109 { |
106 { |
110 DP("The specified filename is not valid!."); |
107 DP("The specified filename is not valid!."); |
111 iSavingResponseBody = EFalse; |
108 iSavingResponseBody = EFalse; |
|
109 iHttpClient->ClientRequestCompleteL(KErrBadName); |
112 } |
110 } |
113 else |
111 else |
114 { |
112 { |
115 if (iContinue) { |
113 if (iContinue) { |
116 TInt err = iRespBodyFile.Open(iFileServ, iParsedFileName.FullName(),EFileWrite); |
114 TInt err = iRespBodyFile.Open(iFileServ, iParsedFileName.FullName(),EFileWrite); |
117 if (err) |
115 if (err) |
118 { |
116 { |
119 DP("There was an error opening file"); |
117 DP2("There was an error opening file '%S', err=%d", &iParsedFileName.FullName(), err); |
120 iSavingResponseBody = EFalse; |
118 iSavingResponseBody = EFalse; |
|
119 iHttpClient->ClientRequestCompleteL(KErrInUse); |
121 User::Leave(err); |
120 User::Leave(err); |
122 } else { |
121 } |
|
122 else |
|
123 { |
123 int pos = -KByteOverlap; |
124 int pos = -KByteOverlap; |
124 if((err=iRespBodyFile.Seek(ESeekEnd, pos)) != KErrNone) { |
125 if((err=iRespBodyFile.Seek(ESeekEnd, pos)) != KErrNone) |
|
126 { |
125 DP("Failed to set position!"); |
127 DP("Failed to set position!"); |
|
128 iHttpClient->ClientRequestCompleteL(KErrWrite); |
126 User::Leave(err); |
129 User::Leave(err); |
|
130 } |
|
131 iBytesDownloaded = (pos > 0) ? pos : 0; |
|
132 iBytesTotal += iBytesDownloaded; |
|
133 DP1("Total bytes is now %u", iBytesTotal); |
|
134 DP1("Seeking end: %d", pos); |
127 } |
135 } |
128 iBytesDownloaded = (pos > 0) ? pos : 0; |
136 } |
129 iBytesTotal += iBytesDownloaded; |
137 else |
130 DP1("Total bytes is now %u", iBytesTotal); |
138 { |
131 DP1("Seeking end: %d", pos); |
|
132 } |
|
133 } else { |
|
134 TInt err = iRespBodyFile.Replace(iFileServ, |
139 TInt err = iRespBodyFile.Replace(iFileServ, |
135 iParsedFileName.FullName(), |
140 iParsedFileName.FullName(), |
136 EFileWrite); |
141 EFileWrite); |
137 if (err) |
142 if (err) |
138 { |
143 { |
158 { |
163 { |
159 TPtrC8 bodyData; |
164 TPtrC8 bodyData; |
160 iRespBody->GetNextDataPart(bodyData); |
165 iRespBody->GetNextDataPart(bodyData); |
161 iBytesDownloaded += bodyData.Length(); |
166 iBytesDownloaded += bodyData.Length(); |
162 TInt error = iRespBodyFile.Write(bodyData); |
167 TInt error = iRespBodyFile.Write(bodyData); |
163 |
168 |
164 // on writing error we close connection |
169 // on writing error we close connection |
165 if (error != KErrNone) { |
170 if (error != KErrNone) { |
166 //aTransaction.Close(); |
171 iRespBodyFile.Close(); |
167 iCallbacks.FileError(error); |
172 iCallbacks.FileError(error); |
168 iHttpClient->ClientRequestCompleteL(error); |
173 iHttpClient->ClientRequestCompleteL(error); |
169 return; |
174 return; |
170 } |
175 } |
171 |
176 |
222 } |
227 } |
223 } break; |
228 } break; |
224 } |
229 } |
225 } |
230 } |
226 |
231 |
227 TInt CHttpEventHandler::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, const THTTPEvent& /*aEvent*/) |
232 TInt CHttpEventHandler::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/) |
228 { |
233 { |
229 DP1("MHFRunError fired with error code %d", aError); |
234 DP1("MHFRunError fired with error code %d", aError); |
230 |
235 aTransaction.Close(); |
|
236 TRAP_IGNORE(iHttpClient->ClientRequestCompleteL(aError)); |
231 return KErrNone; |
237 return KErrNone; |
232 } |
238 } |
233 |
239 |
234 void CHttpEventHandler::SetSaveFileName(const TDesC &fName, TBool aContinue) |
240 void CHttpEventHandler::SetSaveFileName(const TDesC &fName, TBool aContinue) |
235 { |
241 { |