Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Feature/cookies session #46

Closed
wants to merge 5 commits into from
Closed

Feature/cookies session #46

wants to merge 5 commits into from

Conversation

plwai
Copy link
Member

@plwai plwai commented Feb 11, 2020

  • Cookies

  • Session Structure

  • Session middleware

resolve #42

@plwai plwai added the enhancement Enchancement for current feature label Feb 11, 2020
@plwai plwai added this to the V0.2 milestone Feb 11, 2020
@plwai plwai self-assigned this Feb 11, 2020
@plwai plwai added this to In progress in Obsidian via automation Feb 11, 2020
@plwai plwai changed the base branch from master to develop February 11, 2020 09:11
@plwai
Copy link
Member Author

plwai commented Feb 29, 2020

Blocked until #47 completed.

@plwai plwai moved this from In progress to Blocker in Obsidian Feb 29, 2020
src/context.rs Outdated
Comment on lines 276 to 278
if let Some(ref cookie) = cookie_data.cookie_jar().get(name) {
return Some(*cookie);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It it possible to just use:

            return cookie_data.cookie_jar().get(name)


cookie_str
.split("; ")
.map(|x| x.trim().splitn(2, '=').collect::<Vec<&str>>())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it collect as tuple? This does Vec allocation in every loop inside map.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking on if there is extra '=' being sent in the http header. Anyway, the whole cookies session will be revamped as the core flow is being changed.


if let Some(cookies) = response.cookies() {
if let Some(response_headers) = res.headers_mut() {
cookies.iter().for_each(move |cookie| {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many cookies are there to iterate? I thought there should be only one cookie?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set-cookie header can be multiple.

use http::StatusCode;
use hyper::{header, Body};
use serde::ser::Serialize;

pub struct Response {
body: Body,
status: StatusCode,
headers: Option<Vec<(header::HeaderName, &'static str)>>,
headers: Option<Vec<(header::HeaderName, String)>>,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use Cow<&'static str> here to allow both &str and String with just little computation cost? If we want it to be smaller, we can use https://crates.io/crates/beef.

@@ -32,11 +35,15 @@ impl Response {
self.body
}

pub fn headers(&self) -> &Option<Vec<(header::HeaderName, &'static str)>> {
pub fn headers(&self) -> &Option<Vec<(header::HeaderName, String)>> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this, it can also be Cow or AsRef<str> to make use of both.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to do this for multiple headers as Cow does not implement Copy. Conversion from Into<Cow<'static, str>> is not possible.

self
}

pub fn set_cookies(mut self, mut cookies: Vec<Cookie<'static>>) -> Self {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this take &[Cookie<'static>]?

self
}

pub fn set_headers(mut self, headers: Vec<(header::HeaderName, &str)>) -> Self {
Copy link

@pickfire pickfire Apr 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this take &[(header::HeaderName, &str)]?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It set to Vec due to lifetime issue i guess. This is from @jk-gan #34.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh

@plwai plwai removed this from the V0.2 milestone Apr 22, 2020
@@ -33,6 +33,7 @@ serde_json = '1.0.44'
url = '2.1.0'
async-std = '1.4.0'
async-trait = '0.1.22'
cookie = "0.13.3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cookie = "0.13.3"
// testing
cookie = "0.13.3"

@plwai plwai force-pushed the feature/cookies_session branch from 4548009 to e456c1d Compare May 1, 2020 10:00
plwai added 3 commits May 3, 2020 15:15
Implement set cookies using cookies trait as there are a lot of options within cookie properties.
Implement cookie parser middleware. Enable context cookie getter. Fix
context dynamic data get and get_mut return wrong type issue.
Revamp the flow to fit current routing handler. Cookie flow and
convertion are improved in this commit too.
@plwai plwai force-pushed the feature/cookies_session branch from e456c1d to edf1fce Compare May 3, 2020 07:16
@plwai plwai marked this pull request as ready for review May 19, 2020 11:56
@plwai plwai requested a review from jk-gan May 19, 2020 12:02
@plwai plwai closed this May 19, 2020
Obsidian automation moved this from Blocker to Done May 19, 2020
@plwai plwai reopened this May 19, 2020
Obsidian automation moved this from Done to In progress May 19, 2020
@plwai plwai closed this May 19, 2020
Obsidian automation moved this from In progress to Done May 19, 2020
@plwai plwai mentioned this pull request May 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Enchancement for current feature
Projects
Obsidian
  
Done
Development

Successfully merging this pull request may close these issues.

Session cookies support
3 participants