Skip to content

Commit

Permalink
Add HTTP headers for external solver requests (#201)
Browse files Browse the repository at this point in the history
This PR just adds HTTP headers indicating that external solver `/solve` requests both send and only accept JSON.

This is just to be more polite to solvers as some frameworks have friction if the header is missing or not set to `application/json`.

### Test Plan

CI.
  • Loading branch information
Nicholas Rodrigues Lordello authored May 16, 2022
1 parent 4ac71cd commit 9250679
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/shared/src/http_solver.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{anyhow, ensure, Context, Result};
use reqwest::header::HeaderValue;
use reqwest::header::{self, HeaderValue};
use reqwest::{Client, Url};
use std::time::Duration;

Expand Down Expand Up @@ -110,7 +110,12 @@ impl HttpSolverApi for DefaultHttpSolverApi {
.append_pair("auction_id", auction_id.to_string().as_str());
}
let query = url.query().map(ToString::to_string).unwrap_or_default();
let mut request = self.client.post(url).timeout(timeout);
let mut request = self
.client
.post(url)
.timeout(timeout)
.header(header::CONTENT_TYPE, "application/json")
.header(header::ACCEPT, "application/json");
if let Some(api_key) = &self.config.api_key {
let mut header = HeaderValue::from_str(api_key.as_str()).unwrap();
header.set_sensitive(true);
Expand Down

0 comments on commit 9250679

Please sign in to comment.