This document outlines the tasks for refactoring lang_handler to use the standard http crate types instead of custom implementations.
Replace custom Request, Response, and Headers types with types from the http crate, preserving custom functionality through the Extensions API and extension traits.
- Add dependencies to Cargo.toml:
http = "1.0"http-body = "1.0"bytes = "1.0"(already present)
- Create
src/extensions.rsmodule for extension types:-
SocketInfo- store local/remote socket addresses -
ResponseLog- log buffer using Bytes -
ResponseException- exception message storage - Implement Clone, Debug traits for all extensions
-
Create extension traits that add convenience methods to http types:
-
RequestExttrait forhttp::Request<T>:-
socket_info(&self) -> Option<&SocketInfo> -
socket_info_mut(&mut self) -> &mut SocketInfo -
set_socket_info(&mut self, info: SocketInfo)
-
-
ResponseExttrait forhttp::Response<T>:-
log(&self) -> Option<&ResponseLog> -
log_mut(&mut self) -> &mut ResponseLog -
set_log(&mut self, log: impl Into<Bytes>) -
append_log(&mut self, data: impl AsRef<[u8]>) -
exception(&self) -> Option<&ResponseException> -
set_exception(&mut self, exception: impl Into<String>)
-
- Remove custom Request struct and RequestBuilder
- Define type alias:
pub type Request = http::Request<Bytes> - Implement
RequestExtforhttp::Request<T> - Update all Request construction to use
http::Request::builder()
- Remove custom Response struct and ResponseBuilder
- Define type alias:
pub type Response = http::Response<Bytes> - Implement
ResponseExtforhttp::Response<T> - Update all Response construction to use
http::Response::builder()
- Remove custom Headers type and Header enum
- Use
http::HeaderMapdirectly - Update all header operations to use HeaderMap API
- Update Handler trait:
trait Handler { type Error; fn handle(&self, request: http::Request<Bytes>) -> Result<http::Response<Bytes>, Self::Error>; }
- Update all Handler implementations
- Delete old rewrite module as its functionality has been reproduced in a separate crate.
Create intermediate types for NAPI that implement Deref/DerefMut:
-
NapiRequest- wrapshttp::Request<Bytes>- Implement Deref/DerefMut to
http::Request<Bytes> - Implement NAPI conversion traits
- Handle socket info in conversions
- Implement Deref/DerefMut to
-
NapiResponse- wrapshttp::Response<Bytes>- Implement Deref/DerefMut to
http::Response<Bytes> - Implement NAPI conversion traits
- Handle log/exception in conversions
- Implement Deref/DerefMut to
-
NapiHeaders- wrapshttp::HeaderMap- Implement Deref/DerefMut to
http::HeaderMap - Implement NAPI conversion traits
- Maintain multi-value support
- Implement Deref/DerefMut to