Skip to content

Commit 30a2b86

Browse files
authored
Merge pull request #12 from getindata/ESP-98_SinkParameters
ESP-98_SinkParameters - pass headers via properties to Http client
2 parents d578b3e + 1c7c57e commit 30a2b86

25 files changed

+738
-978
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ target
66
/src/main/main.iml
77
/src/test/test.iml
88
/flink-http-connector.iml
9+
/dependency-reduced-pom.xml

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Methods defined in classes located outside "internal" package are considered "public API".
77
Any changes to those methods should be communicated as "not backward compatible" and should be avoided.
88
- Add checkstyle configuration to "dev" folder. Add checkstyle check during maven build
9+
- Add HTTP sink client header configuration via properties.
910

1011
## [0.2.0] - 2022-07-06
1112

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ CREATE TABLE http (
6666
id bigint,
6767
some_field string
6868
) WITH (
69-
'connector' = 'http-sink'
70-
'url' = 'http://example.com/myendpoint'
69+
'connector' = 'http-sink',
70+
'url' = 'http://example.com/myendpoint',
7171
'format' = 'json'
7272
)
7373
```
@@ -82,6 +82,52 @@ Due to the fact that `HttpSink` sends bytes inside HTTP request's body, one can
8282

8383
Other examples of usage of the Table API can be found in [some tests](src/test/java/com/getindata/connectors/http/table/HttpDynamicSinkInsertTest.java).
8484

85+
#### Http headers (currently supported only for HTTP Sink)
86+
It is possible to set HTTP headers that will be added to HTTP request send by sink connector.
87+
Headers are defined via property key `gid.connector.http.sink.header.HEADER_NAME = header value` for example:
88+
`gid.connector.http.sink.header.X-Content-Type-Options = nosniff`.
89+
Properties can be set via Sink builder or Property object:
90+
```java
91+
HttpSink.<String>builder()
92+
.setEndpointUrl("http://example.com/myendpoint")
93+
.setElementConverter(
94+
(s, _context) -> new HttpSinkRequestEntry("POST", s.getBytes(StandardCharsets.UTF_8)))
95+
.setProperty("gid.connector.http.sink.header.X-Content-Type-Options", "nosniff")
96+
.build();
97+
```
98+
or
99+
100+
```java
101+
Properties properties = Properties();
102+
properties.setProperty("gid.connector.http.sink.header.X-Content-Type-Options", "nosniff");
103+
104+
HttpSink.<String>builder()
105+
.setEndpointUrl("http://example.com/myendpoint")
106+
.setElementConverter(
107+
(s, _context) -> new HttpSinkRequestEntry("POST", s.getBytes(StandardCharsets.UTF_8)))
108+
.setProperties(properties)
109+
.build();
110+
```
111+
112+
In Table/SQL API, headers can be set using http sink table DDL. In example below, HTTP request done for `http` table will contain three headers:
113+
- `Origin`
114+
- `X-Content-Type-Options`
115+
- `Content-Type`
116+
117+
```roomsql
118+
CREATE TABLE http (
119+
id bigint,
120+
some_field string
121+
) WITH (
122+
'connector' = 'http-sink',
123+
'url' = 'http://example.com/myendpoint',
124+
'format' = 'json',
125+
'gid.connector.http.sink.header.Origin' = '*',
126+
'gid.connector.http.sink.header.X-Content-Type-Options' = 'nosniff',
127+
'gid.connector.http.sink.header.Content-Type' = 'application/json'
128+
)
129+
```
130+
85131
## Implementation
86132
Implementation of an HTTP source connector is based on Flink's `TableFunction` and `AsyncTableFunction` classes.
87133
To be more specific we are using a `LookupTableSource`. Unfortunately Flink's new unified source interface [2] cannot be used for this type of source.

0 commit comments

Comments
 (0)