1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 15:51:06 +01:00

use insert for protobuf content type header

This commit is contained in:
Rob Ede 2021-03-22 05:30:16 +00:00
parent c8f1d9671c
commit 15d72b1694
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933

View File

@ -250,7 +250,7 @@ pub trait ProtoBufResponseBuilder {
impl ProtoBufResponseBuilder for HttpResponseBuilder { impl ProtoBufResponseBuilder for HttpResponseBuilder {
fn protobuf<T: Message>(&mut self, value: T) -> Result<HttpResponse, Error> { fn protobuf<T: Message>(&mut self, value: T) -> Result<HttpResponse, Error> {
self.append_header((CONTENT_TYPE, "application/protobuf")); self.insert_header((CONTENT_TYPE, "application/protobuf"));
let mut body = Vec::new(); let mut body = Vec::new();
value value
@ -296,10 +296,8 @@ mod tests {
}); });
let req = TestRequest::default().to_http_request(); let req = TestRequest::default().to_http_request();
let resp = protobuf.respond_to(&req).await.unwrap(); let resp = protobuf.respond_to(&req).await.unwrap();
assert_eq!( let ct = resp.headers().get(header::CONTENT_TYPE).unwrap();
resp.headers().get(header::CONTENT_TYPE).unwrap(), assert_eq!(ct, "application/protobuf");
"application/protobuf"
);
} }
#[actix_rt::test] #[actix_rt::test]
@ -309,14 +307,14 @@ mod tests {
assert_eq!(protobuf.err().unwrap(), ProtoBufPayloadError::ContentType); assert_eq!(protobuf.err().unwrap(), ProtoBufPayloadError::ContentType);
let (req, mut pl) = TestRequest::get() let (req, mut pl) = TestRequest::get()
.append_header((header::CONTENT_TYPE, "application/text")) .insert_header((header::CONTENT_TYPE, "application/text"))
.to_http_parts(); .to_http_parts();
let protobuf = ProtoBufMessage::<MyObject>::new(&req, &mut pl).await; let protobuf = ProtoBufMessage::<MyObject>::new(&req, &mut pl).await;
assert_eq!(protobuf.err().unwrap(), ProtoBufPayloadError::ContentType); assert_eq!(protobuf.err().unwrap(), ProtoBufPayloadError::ContentType);
let (req, mut pl) = TestRequest::get() let (req, mut pl) = TestRequest::get()
.append_header((header::CONTENT_TYPE, "application/protobuf")) .insert_header((header::CONTENT_TYPE, "application/protobuf"))
.append_header((header::CONTENT_LENGTH, "10000")) .insert_header((header::CONTENT_LENGTH, "10000"))
.to_http_parts(); .to_http_parts();
let protobuf = ProtoBufMessage::<MyObject>::new(&req, &mut pl) let protobuf = ProtoBufMessage::<MyObject>::new(&req, &mut pl)
.limit(100) .limit(100)