Skip to content

Commit

Permalink
Use Inngest client headers in controller
Browse files Browse the repository at this point in the history
  • Loading branch information
KiKoS0 committed Feb 25, 2024
1 parent 95e029c commit 9a66752
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,33 @@ public abstract class InngestController {
@Autowired
CommHandler commHandler;

private static final HttpHeaders commonHeaders = new HttpHeaders();

static {
String inngestSdk = "inngest-kt:v0.0.1";
commonHeaders.add("x-inngest-sdk", inngestSdk);
private HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
commHandler.getClient().getHeaders().forEach(headers::add);
return headers;
}

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping()
public ResponseEntity<String> index() {
String response = commHandler.introspect();
return ResponseEntity.ok().headers(commonHeaders).body(response);
return ResponseEntity.ok().headers(getHeaders()).body(response);
}

@PutMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@PutMapping()
public ResponseEntity<String> put() {
String response = commHandler.register();
return ResponseEntity.ok().headers(commonHeaders).body(response);
return ResponseEntity.ok().headers(getHeaders()).body(response);
}

@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping()
public ResponseEntity<String> handleRequest(
@RequestParam(name = "fnId") String functionId,
@RequestBody String body
) {
try {
CommResponse response = commHandler.callFunction(functionId, body);

return ResponseEntity.status(response.getStatusCode().getCode()).headers(commonHeaders)
return ResponseEntity.status(response.getStatusCode().getCode()).headers(getHeaders())
.body(response.getBody());
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
Expand Down

0 comments on commit 9a66752

Please sign in to comment.