or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

batch-operations.mdclient-services.mdhttp-transport.mdindex.mdjson-error-handling.mdmedia-operations.mdoauth2-auth.mdutilities.md

http-transport.mddocs/

0

# HTTP Transport

1

2

The Google API Client provides HTTP transport implementations with SSL/TLS support and mutual TLS (mTLS) capabilities for secure communication with Google APIs.

3

4

## Core Imports

5

6

```java

7

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;

8

import com.google.api.client.googleapis.apache.v2.GoogleApacheHttpTransport;

9

import com.google.api.client.googleapis.mtls.MtlsProvider;

10

import com.google.api.client.http.HttpTransport;

11

```

12

13

## Java.net HTTP Transport

14

15

### GoogleNetHttpTransport

16

17

Thread-safe factory for creating `NetHttpTransport` instances configured for Google APIs.

18

19

```java { .api }

20

public final class GoogleNetHttpTransport {

21

public static NetHttpTransport newTrustedTransport()

22

throws GeneralSecurityException, IOException;

23

24

@Beta

25

public static NetHttpTransport newTrustedTransport(MtlsProvider mtlsProvider)

26

throws GeneralSecurityException, IOException;

27

}

28

```

29

30

**Usage Example:**

31

32

```java

33

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;

34

import com.google.api.client.http.HttpTransport;

35

36

// Create a trusted transport with Google's certificate trust store

37

HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

38

39

// Use with mTLS provider (Beta)

40

MtlsProvider mtlsProvider = // ... configure mTLS provider

41

HttpTransport mtlsTransport = GoogleNetHttpTransport.newTrustedTransport(mtlsProvider);

42

```

43

44

## Apache HTTP Transport

45

46

### GoogleApacheHttpTransport

47

48

Utilities for Google APIs based on `ApacheHttpTransport`.

49

50

```java { .api }

51

public final class GoogleApacheHttpTransport {

52

public static ApacheHttpTransport newTrustedTransport()

53

throws GeneralSecurityException, IOException;

54

55

@Beta

56

public static ApacheHttpTransport newTrustedTransport(MtlsProvider mtlsProvider)

57

throws GeneralSecurityException, IOException;

58

}

59

```

60

61

**Usage Example:**

62

63

```java

64

import com.google.api.client.googleapis.apache.v2.GoogleApacheHttpTransport;

65

import com.google.api.client.http.apache.v2.ApacheHttpTransport;

66

67

// Create Apache-based transport

68

ApacheHttpTransport transport = GoogleApacheHttpTransport.newTrustedTransport();

69

70

// Use with custom mTLS configuration

71

MtlsProvider mtlsProvider = // ... configure mTLS provider

72

ApacheHttpTransport mtlsTransport = GoogleApacheHttpTransport.newTrustedTransport(mtlsProvider);

73

```

74

75

## Mutual TLS (mTLS) Support

76

77

### MtlsProvider

78

79

Interface for providing mutual TLS configuration.

80

81

```java { .api }

82

@Beta

83

public interface MtlsProvider {

84

boolean useMtlsClientCertificate();

85

String getKeyStorePassword();

86

KeyStore getKeyStore() throws IOException, GeneralSecurityException;

87

}

88

```

89

90

### MtlsUtils

91

92

Utility class for providing the default mutual TLS provider.

93

94

```java { .api }

95

@Beta

96

public class MtlsUtils {

97

public static MtlsProvider getDefaultMtlsProvider();

98

}

99

```

100

101

**Usage Example:**

102

103

```java

104

import com.google.api.client.googleapis.mtls.MtlsUtils;

105

import com.google.api.client.googleapis.mtls.MtlsProvider;

106

107

// Get the default mTLS provider

108

MtlsProvider provider = MtlsUtils.getDefaultMtlsProvider();

109

110

// Check if mTLS should be used via the provider

111

if (provider.useMtlsClientCertificate()) {

112

HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(provider);

113

}

114

```

115

116

### ContextAwareMetadataJson

117

118

Represents context-aware metadata for mTLS configuration.

119

120

```java { .api }

121

public class ContextAwareMetadataJson extends GenericJson {

122

public List<LibraryInfo> getLibs();

123

public void setLibs(List<LibraryInfo> libs);

124

125

public static class LibraryInfo extends GenericJson {

126

public String getName();

127

public void setName(String name);

128

public String getVersion();

129

public void setVersion(String version);

130

}

131

}

132

```

133

134

## Method Override Support

135

136

### MethodOverride

137

138

HTTP request interceptor for overriding HTTP methods using the `X-HTTP-Method-Override` header.

139

140

```java { .api }

141

public final class MethodOverride implements HttpRequestInitializer, HttpExecuteInterceptor {

142

public static final String HEADER = "X-HTTP-Method-Override";

143

144

public MethodOverride();

145

146

public void initialize(HttpRequest request) throws IOException;

147

public void intercept(HttpRequest request) throws IOException;

148

149

public static final class Builder {

150

public MethodOverride build();

151

public boolean getOverrideAllMethods();

152

public Builder setOverrideAllMethods(boolean overrideAllMethods);

153

}

154

}

155

```

156

157

**Usage Example:**

158

159

```java

160

import com.google.api.client.googleapis.MethodOverride;

161

import com.google.api.client.http.HttpRequestInitializer;

162

163

// Create method override interceptor

164

MethodOverride methodOverride = new MethodOverride();

165

166

// Or with builder for custom configuration

167

MethodOverride customOverride = new MethodOverride.Builder()

168

.setOverrideAllMethods(true)

169

.build();

170

171

// Use as request initializer

172

HttpRequestInitializer requestInitializer = methodOverride;

173

```

174

175

## Types

176

177

### HttpTransport

178

179

Base interface for HTTP transport implementations (from google-http-client library).

180

181

### NetHttpTransport

182

183

Java.net-based HTTP transport implementation.

184

185

### ApacheHttpTransport

186

187

Apache HttpClient-based HTTP transport implementation.

188

189

### KeyStore

190

191

Java security KeyStore for certificate management.

192

193

### GeneralSecurityException

194

195

Exception thrown for general security-related errors.

196

197

### IOException

198

199

Exception thrown for I/O-related errors.