-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #481 from vimeo/fix-crash-for-non-ascii-ua
Allow non ASCII characters as a user agent
- Loading branch information
Showing
3 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...rc/test/java/com/vimeo/networking2/internal/interceptor/UserAgentHeaderInterceptorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.vimeo.networking2.internal.interceptor | ||
|
||
import okhttp3.Call | ||
import okhttp3.Connection | ||
import okhttp3.Interceptor | ||
import okhttp3.Protocol | ||
import okhttp3.Request | ||
import okhttp3.Response | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import java.util.concurrent.TimeUnit | ||
|
||
class UserAgentHeaderInterceptorTest { | ||
|
||
private fun createChain(): Interceptor.Chain = object : Interceptor.Chain { | ||
override fun request(): Request = Request.Builder().url("https://vimeo.com").build() | ||
|
||
override fun proceed(request: Request): Response = Response.Builder() | ||
.request(request) | ||
.protocol(Protocol.HTTP_2) | ||
.code(200) | ||
.message("hello") | ||
.build() | ||
|
||
override fun connection(): Connection = error("Unsupported") | ||
|
||
override fun call(): Call = error("Unsupported") | ||
|
||
override fun connectTimeoutMillis(): Int = error("Unsupported") | ||
|
||
override fun withConnectTimeout(timeout: Int, unit: TimeUnit): Interceptor.Chain = error("Unsupported") | ||
|
||
override fun readTimeoutMillis(): Int = error("Unsupported") | ||
|
||
override fun withReadTimeout(timeout: Int, unit: TimeUnit): Interceptor.Chain = error("Unsupported") | ||
|
||
override fun writeTimeoutMillis(): Int = error("Unsupported") | ||
|
||
override fun withWriteTimeout(timeout: Int, unit: TimeUnit): Interceptor.Chain = error("Unsupported") | ||
} | ||
|
||
@Test | ||
fun `normal characters are supported`() { | ||
assertEquals( | ||
UserAgentHeaderInterceptor(userAgent = "test").intercept(createChain()).request().header("User-Agent"), | ||
"test" | ||
) | ||
} | ||
|
||
@Test | ||
fun `special characters are supported`() { | ||
assertEquals( | ||
UserAgentHeaderInterceptor(userAgent = "test²").intercept(createChain()).request().header("User-Agent"), | ||
"test²" | ||
) | ||
} | ||
} |