|
2 | 2 |
|
3 | 3 | import java.util.HashSet;
|
4 | 4 | import java.util.Set;
|
| 5 | +import java.util.concurrent.ExecutionException; |
5 | 6 |
|
6 | 7 | import com.github.tomakehurst.wiremock.WireMockServer;
|
7 | 8 | import com.github.tomakehurst.wiremock.http.RequestMethod;
|
@@ -162,4 +163,48 @@ public void testHttpDynamicSinkRawFormat() throws Exception {
|
162 | 163 | assertEquals(RequestMethod.POST, request.getMethod());
|
163 | 164 | assertEquals("application/octet-stream", request.getHeader("Content-Type"));
|
164 | 165 | }
|
| 166 | + |
| 167 | + @Test |
| 168 | + public void testHttpRequestWithHeadersFromDdl() |
| 169 | + throws ExecutionException, InterruptedException { |
| 170 | + String originHeaderValue = "*"; |
| 171 | + String xContentTypeOptionsHeaderValue = "nosniff"; |
| 172 | + String contentTypeHeaderValue = "application/json"; |
| 173 | + |
| 174 | + wireMockServer.stubFor(any(urlPathEqualTo("/myendpoint")).willReturn(ok())); |
| 175 | + |
| 176 | + final String createTable = |
| 177 | + String.format( |
| 178 | + "CREATE TABLE http (\n" |
| 179 | + + " last_name string" |
| 180 | + + ") with (\n" |
| 181 | + + " 'connector' = '%s',\n" |
| 182 | + + " 'url' = '%s',\n" |
| 183 | + + " 'format' = 'raw',\n" |
| 184 | + + " 'gid.connector.http.sink.header.Origin' = '%s',\n" |
| 185 | + + " 'gid.connector.http.sink.header.X-Content-Type-Options' = '%s',\n" |
| 186 | + + " 'gid.connector.http.sink.header.Content-Type' = '%s'\n" |
| 187 | + + ")", |
| 188 | + HttpDynamicTableSinkFactory.IDENTIFIER, |
| 189 | + "http://localhost:" + SERVER_PORT + "/myendpoint", |
| 190 | + originHeaderValue, |
| 191 | + xContentTypeOptionsHeaderValue, |
| 192 | + contentTypeHeaderValue |
| 193 | + ); |
| 194 | + |
| 195 | + tEnv.executeSql(createTable); |
| 196 | + |
| 197 | + final String insert = "INSERT INTO http VALUES ('Clee')"; |
| 198 | + tEnv.executeSql(insert).await(); |
| 199 | + |
| 200 | + var postedRequests = wireMockServer.findAll(anyRequestedFor(urlPathEqualTo("/myendpoint"))); |
| 201 | + assertEquals(1, postedRequests.size()); |
| 202 | + |
| 203 | + var request = postedRequests.get(0); |
| 204 | + assertEquals("Clee", request.getBodyAsString()); |
| 205 | + assertEquals(RequestMethod.POST, request.getMethod()); |
| 206 | + assertEquals(contentTypeHeaderValue, request.getHeader("Content-Type")); |
| 207 | + assertEquals(originHeaderValue, request.getHeader("Origin")); |
| 208 | + assertEquals(xContentTypeOptionsHeaderValue, request.getHeader("X-Content-Type-Options")); |
| 209 | + } |
165 | 210 | }
|
0 commit comments