Struct fe_session::FeConnection [] [src]

pub struct FeConnection {
    // some fields omitted
}

A HTTP client connection that is cookie aware.

This object is implemented for testing purposes. It allows for a series of HTTP requests to a server and remmember the cookie's the server has responded with so they can be passed back to the server for the next request.

Examples

use iron::{Iron, Request, Response};
use iron::status::Status;
use fe_session::FeConnection;

let iron = Iron::new(|_ : &mut Request| {
   Ok(Response::with((Status::Ok, "success")))
});
let mut server = iron.http(("localhost", 3000)).unwrap();

let mut conn = FeConnection::new("localhost", 3000);
assert_eq!(conn.get_string("/login?bob"), "success");
assert_eq!(conn.get_string("/logout"), "success");

server.close().unwrap();

Methods

impl FeConnection

fn new(server: &str, port: u16) -> FeConnection

Create a new instance of the object.

Examples

use fe_session::FeConnection;

let conn = FeConnection::new("localhost", 3000);

Returns the value of the specified cookie.

If the cookie doesn't exist this this method will return an empty string.

Sets a cookie to send to the server.

This method would replace any existing cookie with the same name.

fn get_string(&mut self, path: &str) -> String

Issues an HTTP GET request to the server and returns the response as a string. If the connection cannot be made or the server returns an error, this method will return an empty string.

Examples

use iron::{Iron, Request, Response};
use iron::status::Status;
use fe_session::FeConnection;

fn main() {
let iron = Iron::new(|_ : &mut Request| {
   Ok(Response::with((Status::Ok, "success")))
});
let mut server = iron.http(("localhost", 3000)).unwrap();

let mut conn = FeConnection::new("localhost", 3000);
assert_eq!(conn.get_string("/login?bob"), "success");
assert_eq!(conn.get_string("/logout"), "success");

server.close().unwrap();

Trait Implementations

impl Debug for FeConnection

fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>