-
-
Notifications
You must be signed in to change notification settings - Fork 14
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 #12 from Mygod/brotli
Support brotli compression
- Loading branch information
Showing
14 changed files
with
134 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "brotli"] | ||
path = brotli | ||
url = https://github.com/google/brotli.git |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
cmake_minimum_required(VERSION 3.22.1) | ||
project("brotli") | ||
set(BROTLI_DIR "../../../../brotli") | ||
file(GLOB COMMON_SOURCES "${BROTLI_DIR}/c/common/*.c") | ||
file(GLOB ENC_SOURCES "${BROTLI_DIR}/c/enc/*.c") | ||
add_library(${CMAKE_PROJECT_NAME} SHARED | ||
${COMMON_SOURCES} | ||
${ENC_SOURCES} | ||
${BROTLI_DIR}/java/org/brotli/wrapper/enc/encoder_jni.cc | ||
) | ||
target_link_libraries(${CMAKE_PROJECT_NAME} | ||
# List libraries link to the target library | ||
#android | ||
#log | ||
) | ||
include_directories( | ||
${BROTLI_DIR}/c/include | ||
) |
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
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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/be/mygod/reactmap/webkit/PostInterceptor.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,32 @@ | ||
package be.mygod.reactmap.webkit | ||
|
||
import android.util.LongSparseArray | ||
import android.webkit.JavascriptInterface | ||
import android.webkit.WebResourceRequest | ||
import android.webkit.WebView | ||
import be.mygod.reactmap.R | ||
import com.google.common.hash.Hashing | ||
import java.nio.charset.Charset | ||
|
||
class PostInterceptor(private val web: WebView) { | ||
private val bodyLookup = LongSparseArray<String>().also { | ||
web.addJavascriptInterface(this, "_postInterceptor") | ||
} | ||
private val jsSetup = web.resources.openRawResource(R.raw.setup_interceptor).bufferedReader().readText() | ||
|
||
fun setup() = web.evaluateJavascript(jsSetup, null) | ||
|
||
@JavascriptInterface | ||
fun register(body: String): String { | ||
val key = Hashing.sipHash24().hashString(body, Charset.defaultCharset()).asLong() | ||
synchronized(bodyLookup) { bodyLookup.put(key, body) } | ||
return key.toULong().toString(36) | ||
} | ||
fun extractBody(request: WebResourceRequest) = request.requestHeaders.remove("Body-Digest")?.let { key -> | ||
synchronized(bodyLookup) { | ||
val index = bodyLookup.indexOfKey(key.toULong(36).toLong()) | ||
if (index < 0) null else bodyLookup.valueAt(index).also { bodyLookup.removeAt(index) } | ||
} | ||
} | ||
fun clear() = synchronized(bodyLookup) { bodyLookup.clear() } | ||
} |
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
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,7 @@ | ||
window._fetch = window.fetch; | ||
window.fetch = function (input, init = {}) { | ||
if (input === '/graphql' && init.method === 'POST' && init.body) { | ||
init.headers['Body-Digest'] = window._postInterceptor.register(init.body); | ||
} | ||
return window._fetch(input, init); | ||
}; |
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