Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android/jni/JniWebRequest.cpp

Issue 29345369: Issue 4081 - Fix failing MockWebRequestTest test for libadblockplus-android (Closed)
Patch Set: with Utils' JniJavaToStdString Created June 21, 2016, 9:04 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: libadblockplus-android/jni/JniWebRequest.cpp
===================================================================
--- a/libadblockplus-android/jni/JniWebRequest.cpp
+++ b/libadblockplus-android/jni/JniWebRequest.cpp
@@ -11,16 +11,17 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
#include "JniCallbacks.h"
+#include "Utils.h"
static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject)
{
try
{
return JniPtrToLong(new AdblockPlus::WebRequestPtr(new JniWebRequest(env, callbackObject)));
}
CATCH_THROW_AND_RETURN(env, 0)
@@ -72,17 +73,36 @@
if (!env->ExceptionCheck())
{
sResponse.status = JniGetLongField(*env, serverResponseClass->Get(),
*response, "status");
sResponse.responseStatus = JniGetIntField(*env,
serverResponseClass->Get(), *response, "responseStatus");
sResponse.responseText = JniGetStringField(*env,
serverResponseClass->Get(), *response, "response");
- // TODO: transform Headers
+
+ // map headers
+ jobjectArray responseHeadersArray = JniGetStringArrayField(*env,
+ serverResponseClass->Get(), *response, "headers");
+
+ if (responseHeadersArray) {
René Jeschke 2016/07/12 16:22:53 Please pay attention to our coding style, opening
anton 2016/07/13 06:49:52 Acknowledged.
+ int itemsCount = env->GetArrayLength(responseHeadersArray) / 2;
+ for (int i=0; i<itemsCount; i++) {
+ // key
René Jeschke 2016/07/12 16:22:53 This comment is not needed, the variable name spea
anton 2016/07/13 06:49:52 Acknowledged.
+ jstring jKey = (jstring)env->GetObjectArrayElement(responseHeadersArray, i * 2);
+ std::string stdKey = JniJavaToStdString(*env, jKey);
+
+ // value
René Jeschke 2016/07/12 16:22:53 See // key
anton 2016/07/13 06:49:52 Acknowledged.
+ jstring jValue = (jstring)env->GetObjectArrayElement(responseHeadersArray, i * 2 + 1);
+ std::string stdValue = JniJavaToStdString(*env, jValue);
+
+ std::pair<std::string,std::string> keyValue(stdKey, stdValue);
+ sResponse.responseHeaders.push_back(keyValue);
+ }
+ }
}
}
CheckAndLogJavaException(*env);
return sResponse;
}
« .hgignore ('K') | « .hgignore ('k') | libadblockplus-android/jni/Utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld