Skip to content

Commit

Permalink
make some http re-exports more accessible (actix#2171)
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede authored Apr 19, 2021
1 parent b9dbc58 commit db97974
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 20 deletions.
13 changes: 13 additions & 0 deletions actix-http/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changes

## Unreleased - 2021-xx-xx
### Added
* Re-export `http` crate's `Error` type as `error::HttpError`. [#2171]
* Re-export `StatusCode`, `Method`, `Version` and `Uri` at the crate root. [#2171]
* Re-export `ContentEncoding` and `ConnectionType` at the crate root. [#2171]

### Changed
* `header` mod is now public. [#2171]
* `uri` mod is now public. [#2171]

### Removed
* Stop re-exporting `http` crate's `HeaderMap` types in addition to ours. [#2171]

[#2171]: https://github.com/actix/actix-web/pull/2171


## 3.0.0-beta.6 - 2021-04-17
Expand Down
5 changes: 3 additions & 2 deletions actix-http/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use std::{

use bytes::BytesMut;
use derive_more::{Display, Error, From};
use http::uri::InvalidUri;
use http::{header, Error as HttpError, StatusCode};
use http::{header, uri::InvalidUri, StatusCode};
use serde::de::value::Error as DeError;

use crate::{body::Body, helpers::Writer, Response, ResponseBuilder};

pub use http::Error as HttpError;

/// A specialized [`std::result::Result`]
/// for actix web operations
///
Expand Down
30 changes: 27 additions & 3 deletions actix-http/src/header/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
//! Typed HTTP headers, pre-defined `HeaderName`s, traits for parsing and conversion, and other
//! header utility methods.
//! Pre-defined `HeaderName`s, traits for parsing and conversion, and other header utility methods.
use percent_encoding::{AsciiSet, CONTROLS};

pub use http::header::*;
// re-export from http except header map related items
pub use http::header::{
HeaderName, HeaderValue, InvalidHeaderName, InvalidHeaderValue, ToStrError,
};

// re-export const header names
pub use http::header::{
ACCEPT, ACCEPT_CHARSET, ACCEPT_ENCODING, ACCEPT_LANGUAGE, ACCEPT_RANGES,
ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS,
ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN,
ACCESS_CONTROL_EXPOSE_HEADERS, ACCESS_CONTROL_MAX_AGE,
ACCESS_CONTROL_REQUEST_HEADERS, ACCESS_CONTROL_REQUEST_METHOD, AGE, ALLOW, ALT_SVC,
AUTHORIZATION, CACHE_CONTROL, CONNECTION, CONTENT_DISPOSITION, CONTENT_ENCODING,
CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_LOCATION, CONTENT_RANGE,
CONTENT_SECURITY_POLICY, CONTENT_SECURITY_POLICY_REPORT_ONLY, CONTENT_TYPE, COOKIE,
DATE, DNT, ETAG, EXPECT, EXPIRES, FORWARDED, FROM, HOST, IF_MATCH,
IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_RANGE, IF_UNMODIFIED_SINCE, LAST_MODIFIED,
LINK, LOCATION, MAX_FORWARDS, ORIGIN, PRAGMA, PROXY_AUTHENTICATE,
PROXY_AUTHORIZATION, PUBLIC_KEY_PINS, PUBLIC_KEY_PINS_REPORT_ONLY, RANGE, REFERER,
REFERRER_POLICY, REFRESH, RETRY_AFTER, SEC_WEBSOCKET_ACCEPT,
SEC_WEBSOCKET_EXTENSIONS, SEC_WEBSOCKET_KEY, SEC_WEBSOCKET_PROTOCOL,
SEC_WEBSOCKET_VERSION, SERVER, SET_COOKIE, STRICT_TRANSPORT_SECURITY, TE, TRAILER,
TRANSFER_ENCODING, UPGRADE, UPGRADE_INSECURE_REQUESTS, USER_AGENT, VARY, VIA,
WARNING, WWW_AUTHENTICATE, X_CONTENT_TYPE_OPTIONS, X_DNS_PREFETCH_CONTROL,
X_FRAME_OPTIONS, X_XSS_PROTECTION,
};

use crate::error::ParseError;
use crate::HttpMessage;
Expand Down
8 changes: 7 additions & 1 deletion actix-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod config;
#[cfg(feature = "compress")]
pub mod encoding;
mod extensions;
mod header;
pub mod header;
mod helpers;
mod http_message;
mod message;
Expand All @@ -56,14 +56,20 @@ pub use self::builder::HttpServiceBuilder;
pub use self::config::{KeepAlive, ServiceConfig};
pub use self::error::{Error, ResponseError, Result};
pub use self::extensions::Extensions;
pub use self::header::ContentEncoding;
pub use self::http_message::HttpMessage;
pub use self::message::ConnectionType;
pub use self::message::{Message, RequestHead, RequestHeadType, ResponseHead};
pub use self::payload::{Payload, PayloadStream};
pub use self::request::Request;
pub use self::response::Response;
pub use self::response_builder::ResponseBuilder;
pub use self::service::HttpService;

pub use ::http::{uri, uri::Uri};
pub use ::http::{Method, StatusCode, Version};

// TODO: deprecate this mish-mash of random items
pub mod http {
//! Various HTTP related types.
Expand Down
15 changes: 9 additions & 6 deletions actix-http/src/message.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::cell::{Ref, RefCell, RefMut};
use std::net;
use std::rc::Rc;
use std::{
cell::{Ref, RefCell, RefMut},
net,
rc::Rc,
};

use bitflags::bitflags;

use crate::extensions::Extensions;
use crate::header::HeaderMap;
use crate::http::{header, Method, StatusCode, Uri, Version};
use crate::{
header::{self, HeaderMap},
Extensions, Method, StatusCode, Uri, Version,
};

/// Represents various types of connection
#[derive(Copy, Clone, PartialEq, Debug)]
Expand Down
10 changes: 4 additions & 6 deletions actix-http/src/response_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ use futures_core::Stream;

use crate::{
body::{Body, BodyStream, ResponseBody},
error::Error,
extensions::Extensions,
header::{IntoHeaderPair, IntoHeaderValue},
http::{header, Error as HttpError, StatusCode},
error::{Error, HttpError},
header::{self, IntoHeaderPair, IntoHeaderValue},
message::{BoxedResponseHead, ConnectionType, ResponseHead},
Response,
Extensions, Response, StatusCode,
};

/// An HTTP response builder.
Expand Down Expand Up @@ -291,7 +289,7 @@ impl ResponseBuilder {
return None;
}

self.head.as_mut().map(|r| &mut **r)
self.head.as_deref_mut()
}
}

Expand Down
2 changes: 1 addition & 1 deletion actix-test/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


## 0.1.0-beta.2 - 2021-04-17
* * No significant changes from `0.1.0-beta.1`.
* No significant changes from `0.1.0-beta.1`.


## 0.1.0-beta.1 - 2021-04-02
Expand Down
2 changes: 1 addition & 1 deletion src/http/header/content_disposition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ impl fmt::Display for ContentDisposition {
mod tests {
use super::{ContentDisposition, DispositionParam, DispositionType};
use crate::http::header::{Charset, ExtendedValue, HeaderValue};

#[test]
fn test_from_raw_basic() {
assert!(ContentDisposition::from_raw(&HeaderValue::from_static("")).is_err());
Expand Down
1 change: 1 addition & 0 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use actix_http::{
};
use actix_router::{IntoPattern, Path, Resource, ResourceDef, Url};
use actix_service::{IntoServiceFactory, ServiceFactory};
#[cfg(feature = "cookies")]
use cookie::{Cookie, ParseError as CookieParseError};

use crate::dev::insert_slash;
Expand Down

0 comments on commit db97974

Please sign in to comment.