Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ use wreq_util::EmulationOption;
use self::resp::{BlockingResponse, BlockingWebSocket};
use crate::{
client::resp::{Response, WebSocket},
cookie::Jar,
dns::HickoryDnsResolver,
error::Error,
extractor::Extractor,
http::{Method, cookie::Jar},
http::Method,
http1::Http1Options,
http2::Http2Options,
rt::Runtime,
Expand Down
2 changes: 1 addition & 1 deletion src/client/resp/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::{self, Debug};

use pyo3::prelude::*;

use crate::http::header::HeaderMap;
use crate::header::HeaderMap;

/// An entry in the redirect history.
#[pyclass(subclass, str, frozen)]
Expand Down
4 changes: 3 additions & 1 deletion src/client/resp/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ use super::Streamer;
use crate::{
buffer::PyBuffer,
client::{SocketAddr, body::json::Json, future::PyFuture, resp::history::History},
cookie::Cookie,
error::Error,
http::{Version, cookie::Cookie, header::HeaderMap, status::StatusCode},
header::HeaderMap,
http::{StatusCode, Version},
rt::Runtime,
};

Expand Down
4 changes: 3 additions & 1 deletion src/client/resp/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ use wreq::{

use crate::{
client::SocketAddr,
cookie::Cookie,
error::Error,
http::{Version, cookie::Cookie, header::HeaderMap, status::StatusCode},
header::HeaderMap,
http::{StatusCode, Version},
rt::Runtime,
};

Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ use crate::{
client::body::multipart::Multipart,
emulation::{Emulation, EmulationOption},
error::Error,
http::{
Version,
header::{HeaderMap, OrigHeaderMap},
},
header::{HeaderMap, OrigHeaderMap},
http::Version,
proxy::Proxy,
};

Expand Down
File renamed without changes.
60 changes: 57 additions & 3 deletions src/http.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
pub mod cookie;
pub mod header;
pub mod status;
use std::fmt;

use pyo3::prelude::*;

Expand Down Expand Up @@ -29,3 +27,59 @@ define_enum!(
TRACE,
PATCH,
);

/// HTTP status code.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[pyclass(eq, str, frozen)]
pub struct StatusCode(pub wreq::StatusCode);

#[pymethods]
impl StatusCode {
/// Return the status code as an integer.
#[inline]
pub const fn as_int(&self) -> u16 {
self.0.as_u16()
}

/// Check if status is within 100-199.
#[inline]
pub fn is_informational(&self) -> bool {
self.0.is_informational()
}

/// Check if status is within 200-299.
#[inline]
pub fn is_success(&self) -> bool {
self.0.is_success()
}

/// Check if status is within 300-399.
#[inline]
pub fn is_redirection(&self) -> bool {
self.0.is_redirection()
}

/// Check if status is within 400-499.
#[inline]
pub fn is_client_error(&self) -> bool {
self.0.is_client_error()
}

/// Check if status is within 500-599.
#[inline]
pub fn is_server_error(&self) -> bool {
self.0.is_server_error()
}
}

impl From<wreq::StatusCode> for StatusCode {
fn from(status: wreq::StatusCode) -> Self {
Self(status)
}
}

impl fmt::Display for StatusCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
59 changes: 0 additions & 59 deletions src/http/status.rs

This file was deleted.

11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ use tikv_jemallocator as _;
mod macros;
mod buffer;
mod client;
mod cookie;
mod dns;
mod emulation;
mod error;
mod extractor;
mod header;
mod http;
mod http1;
mod http2;
Expand All @@ -35,14 +37,11 @@ use self::{
BlockingResponse, BlockingWebSocket, History, Message, Response, Streamer, WebSocket,
},
},
cookie::{Cookie, Jar, SameSite},
emulation::{Emulation, EmulationOS, EmulationOption},
error::*,
http::{
Method, Version,
cookie::{Cookie, Jar, SameSite},
header::{HeaderMap, OrigHeaderMap},
status::StatusCode,
},
header::{HeaderMap, OrigHeaderMap},
http::{Method, StatusCode, Version},
http1::Http1Options,
http2::{
Http2Options, Priorities, Priority, PseudoId, PseudoOrder, SettingId, SettingsOrder,
Expand Down
1 change: 1 addition & 0 deletions src/status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@