Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support redirects #7

Merged
merged 10 commits into from
May 28, 2019
Merged

Support redirects #7

merged 10 commits into from
May 28, 2019

Conversation

dimamo5
Copy link
Collaborator

@dimamo5 dimamo5 commented May 13, 2019

This PR deprecates Volley in favor of OkHttp.

With this new HTTP client, we can handle redirects just by setting .followRedirects(true) and .followSslRedirects(true). I also noticed that only GET/HEAD requests follow the redirect with the same method. Any request with a different method is changed to a GET request. square/okhttp#2262
To avoid running into some problems in the future, I changed the way we make tracking requests. Previously, the track request was a POST with the event in the body, now the request is a GET and the event is serialized to query parameters (similar to JS tag).

I also updated the changelog with some entries from previous PRs.

@codecov
Copy link

codecov bot commented May 13, 2019

Codecov Report

Merging #7 into master will increase coverage by 0.3%.
The diff coverage is 90.69%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master       #7     +/-   ##
===========================================
+ Coverage     69.17%   69.48%   +0.3%     
  Complexity        1        1             
===========================================
  Files             8        8             
  Lines           146      154      +8     
  Branches         19       21      +2     
===========================================
+ Hits            101      107      +6     
- Misses           37       38      +1     
- Partials          8        9      +1
Impacted Files Coverage Δ Complexity Δ
...cidi-sdk/src/main/kotlin/com/velocidi/Constants.kt 0% <ø> (ø) 0 <0> (ø) ⬇️
...ocidi-sdk/src/main/kotlin/com/velocidi/Velocidi.kt 76.27% <100%> (+0.4%) 0 <0> (ø) ⬇️
velocidi-sdk/src/main/kotlin/com/velocidi/Util.kt 68.75% <100%> (-1.84%) 0 <0> (ø)
...elocidi-sdk/src/main/kotlin/com/velocidi/Config.kt 90.9% <100%> (+5.19%) 0 <0> (ø) ⬇️
...idi-sdk/src/main/kotlin/com/velocidi/HttpClient.kt 83.33% <82.6%> (-1.29%) 1 <0> (ø)
...c/main/kotlin/com/velocidi/GetAdvertisingIdTask.kt 6.66% <0%> (-0.48%) 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 162199a...32f7209. Read the comment docs.

@dimamo5 dimamo5 force-pushed the migrate-to-okhttp branch from ddc92a8 to b1524cc Compare May 13, 2019 14:38
@dimamo5 dimamo5 force-pushed the migrate-to-okhttp branch from b1524cc to 4f9e808 Compare May 13, 2019 14:55

/**
* Http Client based on Android Volley
*
*/
internal class HttpClient {
private val cache = DiskBasedCache(File(Constants.CACHE_DIR), 1024 * 1024) // 1MB cap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CACHE_DIR constant is no longer required it seems.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 211a8b1


companion object {

val JSON_MEDIA_TYPE = MediaType.get("application/json; charset=utf-8")

val defaultListener = object : ResponseListener {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be made private?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved in 211a8b1

@@ -75,17 +74,12 @@ object Util {
* @return URL with the new parameters
*/
@Throws(URISyntaxException::class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it still throw this type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, this function doesn't throw. Removed in e34a461

start()
}
internal class HttpClient {
var client =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be a val?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can. Changed in fdfa6fe

velocidi-sdk/src/main/kotlin/com/velocidi/HttpClient.kt Outdated Show resolved Hide resolved
@@ -16,10 +12,39 @@ abstract class TrackingEvent(
/**
* Serializes the current data model to JSON
*/
open fun serialize(): String {
open fun toJson(): String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we still need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, this method gives more flexibility to SDK users. E.g., they can create a pageView, convert it to JSON and add custom properties and convert it back to a CustomTrackingEvent.

I don't have a strong opinion about this. If you think it's best to be stricter on this matter, I'll remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that is the use case, can't we just provide a method to append custom properties directly from a CustomTrackingEvent?

Copy link
Collaborator Author

@dimamo5 dimamo5 May 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the toJson operation in da4ca9c. I also added the possibility to append proprieties to customTrackingEvents in f929a22.

@Rule
@JvmField
val globalTimeout = Timeout.seconds(10) // 10 seconds max per method tested
// @Rule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these supposed to be left here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readded in fdfa6fe

@dimamo5 dimamo5 force-pushed the migrate-to-okhttp branch from ad1423f to e34a461 Compare May 15, 2019 14:16
@dimamo5 dimamo5 requested a review from thyandrecardoso May 17, 2019 11:03
@thyandrecardoso
Copy link
Contributor

Previously, the track request was a POST with the event in the body, now the request is a GET and the event is serialized to query parameters (similar to JS tag)

From what I understood from here the 302 allows the client to change from POST to GET...?

Did you entertain the possibility of changing our server behavior to reply with 308s?

@dimamo5 dimamo5 force-pushed the migrate-to-okhttp branch from 932e100 to f929a22 Compare May 21, 2019 14:32
@dimamo5
Copy link
Collaborator Author

dimamo5 commented May 21, 2019

From what I understood from here the 302 allows the client to change from POST to GET...?

That's right.

Did you entertain the possibility of changing our server behavior to reply with 308s?

As discussed offline, 308 is a recent HTTP code and may not be supported by some HTTP clients. https://serverfault.com/questions/609872/is-it-safe-to-use-http-status-308-permanent-redirect

@@ -14,6 +14,9 @@ class CustomTrackingEvent(
@Transient
override val gson = defaultGson

fun appendProperty(key: String, value: String) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the value be of type Object?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved in 32f7209.

@@ -11,10 +11,14 @@ class CustomTrackingEvent(
val extraAttributes: JSONObject = JSONObject()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is not from this PR, but if we don't have a concrete use case, I would prefer not to include the functionality to get a CustomTrackingEvent from JSON. Also, I think the exceptions thrown should be custom (like if a given field cannot be extracted from the input JSON) and are, at this moment, generic JSON exceptions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can iterate on this later. I'll create an issue with this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Please leave that issue link here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#8

@thyandrecardoso thyandrecardoso merged commit 03d8961 into master May 28, 2019
@thyandrecardoso thyandrecardoso deleted the migrate-to-okhttp branch May 28, 2019 17:15
@dimamo5 dimamo5 mentioned this pull request Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants