Skip to content

Commit

Permalink
support head requests in proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
bprize15 committed Jun 17, 2024
1 parent f1ef6b9 commit ca05f09
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/org/mskcc/cbio/oncokb/web/rest/ApiProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class ApiProxy {

private String IP_HEADER = "X-FORWARDED-FOR";

@RequestMapping("/**")
@RequestMapping(path = "/**", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.HEAD})
public ResponseEntity<String> proxy(@RequestBody(required = false) String body, HttpMethod method, HttpServletRequest request)
throws URISyntaxException {
URI uri = apiProxyService.prepareURI(request);
Expand All @@ -83,6 +84,10 @@ public ResponseEntity<String> proxy(@RequestBody(required = false) String body,
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));

try {
if (method.equals(HttpMethod.HEAD)) {
ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(body, httpHeaders), String.class);
return new ResponseEntity<>(response.getHeaders(), response.getStatusCode());
}
return restTemplate.exchange(uri, method, new HttpEntity<>(body, httpHeaders), String.class);
} catch (HttpClientErrorException httpClientErrorException) {
if (httpClientErrorException.getStatusCode() != null && httpClientErrorException.getStatusCode().equals(HttpStatus.BAD_REQUEST)) {
Expand Down

0 comments on commit ca05f09

Please sign in to comment.