Skip to content

Commit 0ca0bc9

Browse files
committed
fix: check user_agent for null
1 parent 840d789 commit 0ca0bc9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: src/http/request.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@ impl Request {
211211
/// Client HTTP [User-Agent].
212212
///
213213
/// [User-Agent]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
214-
pub fn user_agent(&self) -> &NgxStr {
215-
unsafe { NgxStr::from_ngx_str((*self.0.headers_in.user_agent).value) }
214+
pub fn user_agent(&self) -> Option<&NgxStr> {
215+
if !self.0.headers_in.user_agent.is_null() {
216+
unsafe { Some(NgxStr::from_ngx_str((*self.0.headers_in.user_agent).value)) }
217+
} else {
218+
None
219+
}
216220
}
217221

218222
/// Set HTTP status of response.

0 commit comments

Comments
 (0)