clockworklabs/SpacetimeDB · error · anyhow::Error
HTTP response from url
Error message
HTTP response from url ({url}) was success but did not have content-type: {content_type} What it means
ResponseExt::ensure_content_type verifies that a successful HTTP response carries exactly the expected Content-Type header before the body is consumed. This specific message fires when the status is a success (2xx) but the header is missing or different. The comparison is exact string equality, so a server sending `application/json; charset=utf-8` will not match an expected `application/json`.
Solutions
- Inspect what is actually served: `curl -sI <url>` and check Content-Type (and Location for redirects)
- Correct the URL to the real artifact/API endpoint (scheme, host, path)
- If you control the server, make the endpoint return the exact expected Content-Type with no extra parameters
- Follow or eliminate redirects so the final response is the artifact itself
Example fix
# before: URL serves an HTML page with 200 $ curl -sI https://host/module.wasm | grep -i content-type content-type: text/html # after: artifact endpoint returns the expected type exactly $ curl -sI https://host/module.wasm | grep -i content-type content-type: application/wasm
Defensive patterns
Strategy: try-catch
Validate before calling
// check before downloading
let resp = client.head(url).send().await?;
let ct = resp.headers().get(http::header::CONTENT_TYPE).and_then(|v| v.to_str().ok());
anyhow::ensure!(ct == Some("application/wasm"), "unexpected content-type {ct:?} at {url}"); Try / catch
match resp.ensure_content_type("application/wasm").await {
Ok(r) => r.bytes().await?,
Err(e) => {
// never parse an HTML page as binary; surface the url + hint instead
return Err(e.context(format!("bad content-type at {url} - is this the artifact endpoint?")));
}
} Prevention
- Validate configured URLs once at startup (HEAD + content-type check) with a clear error
- Follow redirects explicitly or point at the final artifact URL
- Integration-test the endpoint's exact Content-Type, including charset-free values
- Configure proxies/CDNs to preserve the upstream Content-Type
When it happens
Trigger: Passing a URL that returns an HTML page (website root, redirect target, login/placeholder page) where the CLI expects a typed artifact; a reverse proxy serving index.html with 200 for unknown paths; the server appending charset parameters to the content type; a CDN rewriting responses.
Common situations: Wrong --url flag pointing at the marketing site instead of the API/artifact host; nginx `try_files` fallback masking 404s as HTML; trailing-slash redirects landing on an index page; endpoint moved and old URL now serves a page.
Related errors
- {e}
- ( ) from url ( )
- Cannot read environment schema: HTTP
- Environment read failed with HTTP
- Environment read response exceeds limit
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/00d72ba281ec6920.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/util.rs:83
Some("HTTP status server error")
} else {
Some("unexpected HTTP status code")
}
}
impl ResponseExt for reqwest::Response {
async fn ensure_content_type(self, content_type: &str) -> anyhow::Result<Self> {
let status = self.status();
if self
.headers()
.get(http::header::CONTENT_TYPE)
.is_some_and(|ty| ty == content_type)
{
return Ok(self);
}
let url = self.url();
let Some(status_desc) = err_status_desc(status) else {
anyhow::bail!("HTTP response from url ({url}) was success but did not have content-type: {content_type}");
};
let url = url.to_string();
let status_err = match self.error_for_status_ref() {
Err(e) => anyhow::Error::from(e),
Ok(_) => anyhow::anyhow!("{status_desc} ({status}) from url ({url})"),
};
let err = match self.text().await {
Ok(text) => status_err.context(text),
Err(err) => anyhow::Error::from(err)
.context(format!("{status_desc} ({status})"))
.context("failed to get response text"),
};
Err(err)
}
async fn json_or_error<T: serde::de::DeserializeOwned>(self) -> anyhow::Result<T> {
let status = self.status();
self.ensure_content_type("application/json")View on GitHub (pinned to 6dee26c6ef)