forked from nrabulinski/attic
Use common constant for X-Attic-Nar-Info header
This commit is contained in:
parent
54d93ff61f
commit
33d8dfabbd
3 changed files with 9 additions and 7 deletions
|
@ -5,6 +5,9 @@ use crate::cache::CacheName;
|
|||
use crate::hash::Hash;
|
||||
use crate::nix_store::StorePathHash;
|
||||
|
||||
/// Header containing the upload info.
|
||||
pub const ATTIC_NAR_INFO: &str = "X-Attic-Nar-Info";
|
||||
|
||||
/// NAR information associated with a upload.
|
||||
///
|
||||
/// This is JSON-serialized as the value of the `X-Attic-Nar-Info` header.
|
||||
|
|
|
@ -16,7 +16,7 @@ use crate::config::ServerConfig;
|
|||
use crate::version::ATTIC_DISTRIBUTOR;
|
||||
use attic::api::v1::cache_config::{CacheConfig, CreateCacheRequest};
|
||||
use attic::api::v1::get_missing_paths::{GetMissingPathsRequest, GetMissingPathsResponse};
|
||||
use attic::api::v1::upload_path::{UploadPathNarInfo, UploadPathResult};
|
||||
use attic::api::v1::upload_path::{UploadPathNarInfo, UploadPathResult, ATTIC_NAR_INFO};
|
||||
use attic::cache::CacheName;
|
||||
use attic::nix_store::StorePathHash;
|
||||
|
||||
|
@ -177,10 +177,7 @@ impl ApiClient {
|
|||
let req = self
|
||||
.client
|
||||
.put(endpoint)
|
||||
.header(
|
||||
"X-Attic-Nar-Info",
|
||||
HeaderValue::from_str(&upload_info_json)?,
|
||||
)
|
||||
.header(ATTIC_NAR_INFO, HeaderValue::from_str(&upload_info_json)?)
|
||||
.header(USER_AGENT, HeaderValue::from_str(ATTIC_USER_AGENT)?)
|
||||
.body(Body::wrap_stream(stream));
|
||||
|
||||
|
|
|
@ -32,7 +32,9 @@ use crate::config::CompressionType;
|
|||
use crate::error::{ErrorKind, ServerError, ServerResult};
|
||||
use crate::narinfo::Compression;
|
||||
use crate::{RequestState, State};
|
||||
use attic::api::v1::upload_path::{UploadPathNarInfo, UploadPathResult, UploadPathResultKind};
|
||||
use attic::api::v1::upload_path::{
|
||||
UploadPathNarInfo, UploadPathResult, UploadPathResultKind, ATTIC_NAR_INFO,
|
||||
};
|
||||
use attic::hash::Hash;
|
||||
use attic::stream::StreamHasher;
|
||||
use attic::util::Finally;
|
||||
|
@ -116,7 +118,7 @@ pub(crate) async fn upload_path(
|
|||
) -> ServerResult<Json<UploadPathResult>> {
|
||||
let upload_info: UploadPathNarInfo = {
|
||||
let header = headers
|
||||
.get("X-Attic-Nar-Info")
|
||||
.get(ATTIC_NAR_INFO)
|
||||
.ok_or_else(|| ErrorKind::RequestError(anyhow!("X-Attic-Nar-Info must be set")))?;
|
||||
|
||||
serde_json::from_slice(header.as_bytes()).map_err(ServerError::request_error)?
|
||||
|
|
Loading…
Reference in a new issue