Skip to content

Commit

Permalink
Supports HTTP/2
Browse files Browse the repository at this point in the history
  • Loading branch information
vvb2060 committed Apr 29, 2022
1 parent b0b4af2 commit 110af70
Show file tree
Hide file tree
Showing 19 changed files with 251 additions and 20 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Copy version files
shell: bash
run: |
cp curl/src/main/native/config/versions/nghttp2ver.h curl/src/main/native/nghttp2/lib/includes/nghttp2/nghttp2ver.h
cp curl/src/main/native/config/versions/nghttp3ver.h curl/src/main/native/nghttp3/lib/includes/nghttp3/version.h
cp curl/src/main/native/config/versions/ngtcp2ver.h curl/src/main/native/ngtcp2/lib/includes/ngtcp2/version.h
- name: Build with Gradle
run: |
./gradlew assemble
./gradlew :e:assemble
./gradlew publishToMavenLocal
- name: Upload app
uses: actions/upload-artifact@v2
Expand Down
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[submodule "curl/src/main/native/curl"]
path = curl/src/main/native/curl
url = https://github.com/curl/curl.git
[submodule "curl/src/main/native/nghttp2"]
path = curl/src/main/native/nghttp2
url = https://github.com/nghttp2/nghttp2.git
[submodule "curl/src/main/native/ngtcp2"]
path = curl/src/main/native/ngtcp2
url = https://github.com/ngtcp2/ngtcp2.git
[submodule "curl/src/main/native/nghttp3"]
path = curl/src/main/native/nghttp3
url = https://github.com/ngtcp2/nghttp3.git
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
curl static library prefab for android.

Supports SSL, powered by [BoringSSL](https://github.com/vvb2060/BoringSSL_Android).
Supports HTTP/2. powered by [nghttp2](https://github.com/nghttp2/nghttp2).
For HTTP/3 support, wait for curl support for BoringSSL-based [ngtcp2](https://github.com/ngtcp2/ngtcp2).
No other protocols supported.
By default, use system built-in CA certificate store, and use system built-in DNS.
If you want to support HTTP/2, you need to link [nghttp2](https://curl.se/docs/http2.html);
if you want to support HTTP/3, you need to link [quiche](https://curl.se/docs/http3.html).

## Integration

Gradle:

```gradle
implementation 'io.github.vvb2060.ndk:curl:7.83.0'
implementation 'io.github.vvb2060.ndk:curl:7.83.0-h2'
```

This library is [Prefab](https://google.github.io/prefab/), so you will need to enable it in your project (Android Gradle Plugin 4.1+):
Expand Down
16 changes: 14 additions & 2 deletions curl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 32
versionCode 2
versionName '7.83.0'
versionCode 3
versionName '7.83.0-h2'
externalNativeBuild {
ndkBuild {
arguments "-j${Runtime.runtime.availableProcessors()}"
Expand All @@ -39,6 +39,18 @@ android {
curl_static {
headers "src/main/native/curl/include"
}
nghttp2_static {
headers "src/main/native/nghttp2/lib/includes"
}
ngtcp2_static {
headers "src/main/native/ngtcp2/lib/includes"
}
ngtcp2_crypto_static {
headers "src/main/native/ngtcp2/crypto/includes"
}
nghttp3_static {
headers "src/main/native/nghttp3/lib/includes"
}
}

publishing {
Expand Down
58 changes: 53 additions & 5 deletions curl/src/main/native/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,67 @@ LOCAL_MODULE := curl_static
LOCAL_SRC_FILES := $(addprefix curl/lib/,$(CSOURCES))
LOCAL_C_INCLUDES := $(LOCAL_PATH)/curl/include $(LOCAL_PATH)/curl/lib
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config32
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config32
else ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config64
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config64
else ifeq ($(TARGET_ARCH_ABI),x86)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config32
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config32
else ifeq ($(TARGET_ARCH_ABI),x86_64)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config64
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config64
endif
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/curl/include
LOCAL_EXPORT_LDLIBS := -lz
LOCAL_CFLAGS := -DHAVE_CONFIG_H -DBUILDING_LIBCURL
LOCAL_STATIC_LIBRARIES := ssl_static
LOCAL_STATIC_LIBRARIES := ssl_static nghttp2_static
# https://gist.github.com/vvb2060/56d5b8fda2553f36938b2b72b1390114/f8bb9882cbff921ba0dc643e5d15beb93b87700e
STATIC_LIBRARY_STRIP := true
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
include $(LOCAL_PATH)/nghttp2/lib/Makefile.am
LOCAL_MODULE := nghttp2_static
LOCAL_SRC_FILES := $(addprefix nghttp2/lib/,$(OBJECTS))
LOCAL_C_INCLUDES := $(LOCAL_PATH)/nghttp2/lib/includes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/nghttp2/lib/includes
LOCAL_CFLAGS := -DHAVE_CONFIG_H
STATIC_LIBRARY_STRIP := true
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
include $(LOCAL_PATH)/ngtcp2/lib/Makefile.am
LOCAL_MODULE := ngtcp2_static
LOCAL_SRC_FILES := $(addprefix ngtcp2/lib/,$(OBJECTS))
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ngtcp2/lib/includes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ngtcp2/lib/includes
LOCAL_CFLAGS := -DHAVE_CONFIG_H
LOCAL_STATIC_LIBRARIES := ngtcp2_crypto_static
STATIC_LIBRARY_STRIP := true
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
include $(LOCAL_PATH)/ngtcp2/crypto/boringssl/Makefile.am
LOCAL_MODULE := ngtcp2_crypto_static
LOCAL_SRC_FILES += $(addprefix ngtcp2/crypto/boringssl/,$(libngtcp2_crypto_boringssl_a_SOURCES))
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ngtcp2/lib $(LOCAL_PATH)/ngtcp2/lib/includes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/ngtcp2/crypto $(LOCAL_PATH)/ngtcp2/crypto/includes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ngtcp2/crypto/includes
LOCAL_CFLAGS := -DHAVE_CONFIG_H
LOCAL_STATIC_LIBRARIES := ssl_static
STATIC_LIBRARY_STRIP := true
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
include $(LOCAL_PATH)/nghttp3/lib/Makefile.am
LOCAL_MODULE := nghttp3_static
LOCAL_SRC_FILES := $(addprefix nghttp3/lib/,$(OBJECTS))
LOCAL_C_INCLUDES := $(LOCAL_PATH)/nghttp3/lib/includes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/config
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/nghttp3/lib/includes
LOCAL_CFLAGS := -DHAVE_CONFIG_H
STATIC_LIBRARY_STRIP := true
include $(BUILD_STATIC_LIBRARY)

$(call import-module,prefab/boringssl)
8 changes: 8 additions & 0 deletions curl/src/main/native/config/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#define HAVE_NETINET_IN_H 1
#define HAVE_ARPA_INET_H 1
#define HAVE_UNISTD_H 1
#define HAVE_SYS_ENDIAN_H 1
#define HAVE_ENDIAN_H 1
#define HAVE_BYTESWAP_H 1
#define HAVE_BE64TOH 1
#define HAVE_BSWAP_64 1
42 changes: 42 additions & 0 deletions curl/src/main/native/config/versions/nghttp2ver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2012, 2013 Tatsuhiro Tsujikawa
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP2VER_H
#define NGHTTP2VER_H

/**
* @macro
* Version number of the nghttp2 library release
*/
#define NGHTTP2_VERSION "1.47.0"

/**
* @macro
* Numerical representation of the version number of the nghttp2 library
* release. This is a 24 bit number with 8 bits for major number, 8 bits
* for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203.
*/
#define NGHTTP2_VERSION_NUM 0x012f00

#endif /* NGHTTP2VER_H */
46 changes: 46 additions & 0 deletions curl/src/main/native/config/versions/nghttp3ver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2016 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_VERSION_H
#define NGHTTP3_VERSION_H

/**
* @macro
*
* Version number of the nghttp3 library release.
*/
#define NGHTTP3_VERSION "0.4.0"

/**
* @macro
*
* Numerical representation of the version number of the nghttp3
* library release. This is a 24 bit number with 8 bits for major
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
* becomes 0x010203.
*/
#define NGHTTP3_VERSION_NUM 0x000400

#endif /* NGHTTP3_VERSION_H */
51 changes: 51 additions & 0 deletions curl/src/main/native/config/versions/ngtcp2ver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* ngtcp2
*
* Copyright (c) 2016 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef VERSION_H
#define VERSION_H

/**
* @macrosection
*
* Library version macros
*/

/**
* @macro
*
* Version number of the ngtcp2 library release.
*/
#define NGTCP2_VERSION "0.4.0"

/**
* @macro
*
* Numerical representation of the version number of the ngtcp2
* library release. This is a 24 bit number with 8 bits for major
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
* becomes 0x010203.
*/
#define NGTCP2_VERSION_NUM 0x000400

#endif /* VERSION_H */
6 changes: 3 additions & 3 deletions curl/src/main/native/config32/curl_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
/* #undef CURL_DISABLE_VERBOSE_STRINGS */

/* Definition to make a library symbol externally visible. */
#define CURL_EXTERN_SYMBOL
#define CURL_EXTERN_SYMBOL

/* IP address type in sockaddr */
#define CURL_SA_FAMILY_T sa_family_t
Expand Down Expand Up @@ -861,7 +861,7 @@
#define RECV_TYPE_RETV int

/* Define to the type qualifier of arg 5 for select. */
#define SELECT_QUAL_ARG5
#define SELECT_QUAL_ARG5

/* Define to the type of arg 1 for select. */
#define SELECT_TYPE_ARG1 int
Expand Down Expand Up @@ -971,7 +971,7 @@
/* #undef USE_MSH3 */

/* if nghttp2 is in use */
/* #undef USE_NGHTTP2 */
#define USE_NGHTTP2 1

/* if nghttp3 is in use */
/* #undef USE_NGHTTP3 */
Expand Down
6 changes: 3 additions & 3 deletions curl/src/main/native/config64/curl_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
/* #undef CURL_DISABLE_VERBOSE_STRINGS */

/* Definition to make a library symbol externally visible. */
#define CURL_EXTERN_SYMBOL
#define CURL_EXTERN_SYMBOL

/* IP address type in sockaddr */
#define CURL_SA_FAMILY_T sa_family_t
Expand Down Expand Up @@ -861,7 +861,7 @@
#define RECV_TYPE_RETV ssize_t

/* Define to the type qualifier of arg 5 for select. */
#define SELECT_QUAL_ARG5
#define SELECT_QUAL_ARG5

/* Define to the type of arg 1 for select. */
#define SELECT_TYPE_ARG1 int
Expand Down Expand Up @@ -971,7 +971,7 @@
/* #undef USE_MSH3 */

/* if nghttp2 is in use */
/* #undef USE_NGHTTP2 */
#define USE_NGHTTP2 1

/* if nghttp3 is in use */
/* #undef USE_NGHTTP3 */
Expand Down
1 change: 1 addition & 0 deletions curl/src/main/native/nghttp2
Submodule nghttp2 added at d9f580
1 change: 1 addition & 0 deletions curl/src/main/native/nghttp3
Submodule nghttp3 added at 149f0d
1 change: 1 addition & 0 deletions curl/src/main/native/ngtcp2
Submodule ngtcp2 added at e7d58a
5 changes: 4 additions & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ android {

buildTypes {
release {
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.debug
proguardFiles 'proguard-rules.pro'
}
}

Expand All @@ -47,5 +50,5 @@ android {
}

dependencies {
implementation 'io.github.vvb2060.ndk:curl:7.83.0'
implementation 'io.github.vvb2060.ndk:curl:7.83.0-h2'
}
2 changes: 2 additions & 0 deletions example/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-repackageclasses
-allowaccessmodification
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
apkPath = getApplicationInfo().sourceDir;
executor.submit(this::test32Bit);
append("\n");
executor.submit(this::test64Bit);
}
}
1 change: 1 addition & 0 deletions example/src/main/native/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ LOCAL_STATIC_LIBRARIES := curl_static
LOCAL_LDFLAGS := -fPIE
include $(LOCAL_PATH)/build-executable.mk

#include $(LOCAL_PATH)/../../../../curl/src/main/native/Android.mk
$(call import-module,prefab/curl)
Loading

0 comments on commit 110af70

Please sign in to comment.