-
-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL queries #146
URL queries #146
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
flake8==4.0.1 | ||
black==21.12b0 | ||
websockets==10.1 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ use std::sync::atomic::AtomicBool; | |
use std::sync::atomic::Ordering::{Relaxed, SeqCst}; | ||
use std::sync::{Arc, RwLock}; | ||
use std::thread; | ||
use std::collections::HashMap; | ||
|
||
use actix_files::Files; | ||
use actix_http::KeepAlive; | ||
|
@@ -234,6 +235,16 @@ async fn index( | |
mut payload: web::Payload, | ||
req: HttpRequest, | ||
) -> impl Responder { | ||
let mut queries = HashMap::new(); | ||
|
||
if req.query_string().len() > 0 { | ||
let split = req.query_string().split("&"); | ||
for s in split { | ||
let params = s.split_once("=").unwrap_or((s, "")); | ||
queries.insert(params.0, params.1); | ||
} | ||
} | ||
|
||
Comment on lines
+238
to
+247
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want the queries hashmap to be available in every HTTP request or just the GET requests methods? I usually use this kind of params in GET requests only. But I am not sure about the standard of WEB requests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I think it's generally only necessary for GET requests. That being said, this project doesn't exist for just me. I expect developers will want to use features like this in unorthodox ways. There didn't seem to be a good reason to restrict queries solely to GET requests, so I left it open to all types. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Absolutely! Robyn is based on making unorthodox tradeoffs for better performance. I love it. :D |
||
match router.get_route(req.method().clone(), req.uri().path()) { | ||
Some(((handler_function, number_of_params), route_params)) => { | ||
handle_request( | ||
|
@@ -243,6 +254,7 @@ async fn index( | |
&mut payload, | ||
&req, | ||
route_params, | ||
queries, | ||
) | ||
.await | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add this in the dev requirements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While trying to build and test robyn, I ran into an issue where the
websockets
dependency hadn't been met. I looked around, and it gets called inrobyn/integration_tests/test_web_sockets.py
. Since it isn't necessary for normal operation, it seemed more appropriate to add it todev-requirements.txt
. I suppose it isn't really necessary for this to be included for the feature, but I felt like it was worth slipping it in to help with long term CI/CD.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that makes sense. Thank you! :D