Defines the APIs of the HTTP global interceptor module, which includes read-only interceptors and writable interceptors. With global read-only interceptors, you can monitor all HTTP requests initiated by the application through supported system network components to implement the logging feature. With global writable interceptors, you can add custom logic to modify the request headers, response headers, and response bodies of HTTP requests initiated by the application through supported system network components.
Read-only interceptors are supported since API version 24. Writable interceptors are supported since API version 26.0.0.
Restrictions on read-only interceptors: Do not modify the request and response content or release the pointer in a read-only interceptor. Even if you modify the content, the modification will not take effect on the request, but may affect the subsequent read-only interceptors' reading of the data packet content. In addition, setting OH_ABORT in a read-only interceptor will not take effect.
Supported components:
Trigger conditions:
Header file: <network/netstack/http_interceptor.h>
Library: libhttp_interceptor.so
System capability: SystemCapability.Communication.NetStack
Since: 24
Related module: netstack
| Name | Description |
|---|---|
| int32_t OH_Http_AddReadOnlyInterceptor(struct OH_Http_Interceptor *interceptor) | Adds a global read-only HTTP interceptor. |
| int32_t OH_Http_AddWritableInterceptor(struct OH_Http_Interceptor *interceptor) | Adds a global writable interceptor for HTTP. |
| int32_t OH_Http_RemoveInterceptor(struct OH_Http_Interceptor *interceptor) | Removes a specified global HTTP interceptor. |
| int32_t OH_Http_RemoveAllInterceptors(int32_t groupId) | Removes all HTTP interceptors of a specified group ID. |
| int32_t OH_Http_StartAllInterceptors(int32_t groupId) | Enables all HTTP interceptors of a specified group ID. |
| int32_t OH_Http_StopAllInterceptors(int32_t groupId) | Disables all HTTP interceptors of a specified group ID. |
int32_t OH_Http_AddReadOnlyInterceptor(struct OH_Http_Interceptor *interceptor)
Description
Adds a global read-only HTTP interceptor.
System capability: SystemCapability.Communication.NetStack
Required permissions: ohos.permission.INTERNET
Since: 24
Parameters
| Name | Description |
|---|---|
| struct OH_Http_Interceptor *interceptor | Pointer to the OH_Http_Interceptor struct, which is the interceptor to be added. |
Returns
| Type | Description |
|---|---|
| int32_t | If the return value is 0, the execution is successful. If the return value is 201, the permission is denied. If the return value is 401, the parameter is incorrect (for example, the pointer is nullptr, or the added interceptor type is not supported). For details about the error codes, see OH_HTTP_RESULT_OK, OH_HTTP_PERMISSION_DENIED, and OH_HTTP_PARAMETER_ERROR. |
int32_t OH_Http_AddWritableInterceptor(struct OH_Http_Interceptor *interceptor)
Description
Adds a global writable HTTP interceptor.
System capability: SystemCapability.Communication.NetStack
Required permissions: ohos.permission.INTERNET
Since: 26.0.0
Parameters
| Name | Description |
|---|---|
| struct OH_Http_Interceptor *interceptor | Pointer to the OH_Http_Interceptor struct to be added. |
Returns
| Type | Description |
|---|---|
| int32_t | If the return value is 0, the execution is successful. If the return value is 201, the permission is denied. If the return value is 401, the parameter is incorrect (for example, the pointer is nullptr or the added interceptor type is not supported). For details about the error codes, see OH_HTTP_RESULT_OK, OH_HTTP_PERMISSION_DENIED, and OH_HTTP_PARAMETER_ERROR. |
int32_t OH_Http_RemoveInterceptor(struct OH_Http_Interceptor *interceptor)
Description
Removes a specified global HTTP interceptor.
System capability: SystemCapability.Communication.NetStack
Required permissions: ohos.permission.INTERNET
Since: 24
Parameters
| Name | Description |
|---|---|
| struct OH_Http_Interceptor *interceptor | Pointer to the OH_Http_Interceptor struct to be removed. |
Returns
| Type | Description |
|---|---|
| int32_t | If the return value is 0, the execution is successful. If the return value is 201, the permission is denied. If the return value is 401, the parameter is incorrect (for example, the pointer is nullptr). For details about the error codes, see OH_HTTP_RESULT_OK, OH_HTTP_PERMISSION_DENIED, and OH_HTTP_PARAMETER_ERROR. |
int32_t OH_Http_RemoveAllInterceptors(int32_t groupId)
Description
Removes all HTTP interceptors of a specified group ID.
System capability: SystemCapability.Communication.NetStack
Required permissions: ohos.permission.INTERNET
Since: 24
Parameters
| Name | Description |
|---|---|
| int32_t groupId | Interceptor group ID. |
Returns
| Type | Description |
|---|---|
| int32_t | If the return value is 0, the execution is successful. If the return value is 201, the permission is denied. For details about the error codes, see OH_HTTP_RESULT_OK and OH_HTTP_PERMISSION_DENIED. |
int32_t OH_Http_StartAllInterceptors(int32_t groupId)
Description
Enables all HTTP interceptors of a specified group ID.
System capability: SystemCapability.Communication.NetStack
Required permissions: ohos.permission.INTERNET
Since: 24
Parameters
| Name | Description |
|---|---|
| int32_t groupId | Interceptor group ID. |
Returns
| Type | Description |
|---|---|
| int32_t | If the return value is 0, the execution is successful. If the return value is 201, the permission is denied. For details about the error codes, see OH_HTTP_RESULT_OK and OH_HTTP_PERMISSION_DENIED. |
int32_t OH_Http_StopAllInterceptors(int32_t groupId)
Description
Disables all HTTP interceptors of a specified group ID.
System capability: SystemCapability.Communication.NetStack
Required permissions: ohos.permission.INTERNET
Since: 24
Parameters
| Name | Description |
|---|---|
| int32_t groupId | Interceptor group ID. |
Returns
| Type | Description |
|---|---|
| int32_t | If the return value is 0, the execution is successful. If the return value is 201, the permission is denied. For details about the error codes, see OH_HTTP_RESULT_OK and OH_HTTP_PERMISSION_DENIED. |