Skip to content

Commit

Permalink
support headers on raw requests also
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Oct 9, 2023
1 parent 3856fb9 commit 06efed2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
3 changes: 2 additions & 1 deletion bs_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async fn raw_reader(server: Data<Arc<BsServer>>, req: HttpRequest) -> HttpRespon
RouteResolver::RawString(RawString { raw, headers }) => {
let mut res = HttpResponse::Ok().body(raw.clone());
let h = res.headers_mut();
// todo: append mime-type headers here
for (k, v) in headers.iter() {
h.append(
HeaderName::from_bytes(k.as_bytes()).unwrap(),
Expand All @@ -47,14 +48,14 @@ async fn raw_reader(server: Data<Arc<BsServer>>, req: HttpRequest) -> HttpRespon
let named_file = NamedFile::open_async(file).await.unwrap();
let mut res = named_file.into_response(&req);
let h = res.headers_mut();
// todo: append mime-type headers here
for (k, v) in h_m.iter() {
h.append(
HeaderName::from_bytes(k.as_bytes()).unwrap(),
HeaderValue::from_bytes(v.as_bytes()).unwrap(),
);
}
res
// HttpResponse::NotImplemented().body("n")
}
RouteResolver::DirPath(_) => HttpResponse::NotImplemented().body("n"),
}
Expand Down
29 changes: 19 additions & 10 deletions examples/one-file/site.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
servers:
server_a:
routes:
- path: /testing.html
- path: /
raw: |
<!doctype html>
<html lang="en">
Expand All @@ -10,23 +10,32 @@ servers:
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link href="styles.css" rel="stylesheet" />
</head>
<body>
<iframe src="/iframe.html" />
<iframe src="/iframe.html"></iframe>
<script src="/js.js" type=module></script>
</body>
</html>
- path: /js.js
raw: |
import a from "b.js"
- path: /b.js
raw: |
console.log(import.meta)
- path: /iframe.html
headers:
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors https://example.com
Content-Security-Policy: frame-ancestors 'self'
raw: |
<h2> 🙈 Hello from iframe.html</h2>
# - path: /
# dir: ./
- path: /haha.css
headers:
shane: "kittens"
sally: "other"
file: ./style.css
# - path: /
# dir: ./
- path: /styles.css
raw: |
@import url("other.css");
- path: /other.css
raw: |
body { background: red }
# - path: /
# dir: ./

0 comments on commit 06efed2

Please sign in to comment.