目录

http_interceptor.h

Overview

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.

Header file: <network/netstack/http_interceptor.h>

Library: libhttp_interceptor.so

System capability: SystemCapability.Communication.NetStack

Since: 24

Related module: netstack

Summary

[h2]Function

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.

Function Description

[h2]OH_Http_AddReadOnlyInterceptor()

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.

[h2]OH_Http_AddWritableInterceptor()

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.

[h2]OH_Http_RemoveInterceptor()

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.

[h2]OH_Http_RemoveAllInterceptors()

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.

[h2]OH_Http_StartAllInterceptors()

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.

[h2]OH_Http_StopAllInterceptors()

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.