Permalink
Browse files

Fix ids generation. Fix request encoding

  • Loading branch information...
itkacher committed Nov 21, 2018
1 parent 5e1fd76 commit fa12955fff32b2481f054d70449e93b0a5a1bcb5
@@ -46,6 +46,6 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.google.code.gson:gson:2.8.5'
// implementation project(path: ':okhttpprofiler')
implementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.4'
implementation project(path: ':okhttpprofiler')
// implementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.4'
}
@@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 2
versionName "1.0.4"
versionCode 5
versionName "1.0.5"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
@@ -46,7 +46,7 @@ ext {
siteUrl = 'https://github.com/itkacher/OkHttpProfiler'
gitUrl = 'https://github.com/itkacher/OkHttpProfiler.git'

libraryVersion = '1.0.4'
libraryVersion = '1.0.5'

developerId = 'itkacher'
developerName = 'Ievgenii Tkachenko'
@@ -2,7 +2,7 @@
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

version '1.0.4'
version '1.0.5'

publishing {
publications {
@@ -5,6 +5,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicLong;

import com.itkacher.okhttpprofiler.transfer.LogDataTransfer;
import com.itkacher.okhttpprofiler.transfer.DataTransfer;
@@ -19,6 +20,7 @@

private final DataTransfer dataTransfer = new LogDataTransfer();
private final DateFormat format = new SimpleDateFormat("ddhhmmssSSS", Locale.US);
private final AtomicLong previousTime = new AtomicLong();

@Override
public Response intercept(Chain chain) throws IOException {
@@ -37,8 +39,19 @@ public Response intercept(Chain chain) throws IOException {
}
}

private String generateId() {
long timeAndDay = Long.parseLong(format.format(new Date()));
return Long.toString(timeAndDay, Character.MAX_RADIX);
/**
* Generates unique string id via a day and time
* Based on a current time.
* @return string id
*/
private synchronized String generateId() {
long currentTime = Long.parseLong(format.format(new Date()));
//Increase time if it the same, as previous (unique id)
long previousTime = this.previousTime.get();
if(currentTime <= previousTime) {
currentTime = ++previousTime;
}
this.previousTime.set(currentTime);
return Long.toString(currentTime, Character.MAX_RADIX);
}
}
@@ -10,6 +10,7 @@
import android.util.Log;

import java.io.IOException;
import java.nio.charset.Charset;

import okhttp3.Headers;
import okhttp3.MediaType;
@@ -73,7 +74,7 @@ public void sendRequest(String id, Request request) throws IOException {

if (body != null) {
body.writeTo(buffer);
largeLog(id, MessageType.REQUEST_BODY, buffer.readUtf8());
largeLog(id, MessageType.REQUEST_BODY, buffer.readString(Charset.defaultCharset()));
}
}

This file was deleted.

Oops, something went wrong.

0 comments on commit fa12955

Please sign in to comment.