Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillich committed Mar 29, 2016
0 parents commit a37d50b
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
Cargo.lock
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "hyperdav"
version = "0.1.0"
authors = ["Jakob Gillich <jakob@gillich.me>"]

[dependencies]
serde = "0.7"
serde_json = "0.7"
serde_macros = "0.7"
hyper = { version = "0.8.0", features = [ "serde-serialization" ] }
url = "0.5.7"
uuid = "0.1"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Jakob Gillich <jakob@gillich.me>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# hyperdav

One day, this might turn into a usable WebDAV implementation in Rust.

RFC 4918: https://tools.ietf.org/html/rfc4918
42 changes: 42 additions & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use hyper::client::Client as HttpClient;
use hyper::client::RequestBuilder;
use hyper::method::Method;
use hyper::client::IntoUrl;
use hyper::client::Body;
use std::io::Read;
use hyper::header::{Authorization, Basic};

pub struct Client {
http_client: HttpClient,
}

impl Client {
pub fn new() -> Self {
Client {
http_client: HttpClient::new(),
}
}

pub fn put<'a, U: IntoUrl>(&'a self, body: &'a mut Read, url: U) -> RequestBuilder<'a> {
self.request(Method::Put, url).body(Body::ChunkedBody(body))
}

// FIXME this function is a mess
pub fn request<'a, U: IntoUrl>(&'a self, method: Method, url: U) -> RequestBuilder<'a> {
let actual_url = url.into_url().unwrap(); // FIXME :/

let mut req = self.http_client.request(method, actual_url.clone());

// Set auth header
if let Some(scheme) = actual_url.relative_scheme_data() {
if scheme.username != "" {
req = req.header(Authorization(Basic {
username: scheme.username.clone(),
password: scheme.password.clone(),
}));
}
}

req
}
}
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(custom_derive, plugin, question_mark)]
#![plugin(serde_macros)]

extern crate hyper;
extern crate url;

pub mod client;
pub mod webdav;

pub use client::Client;
Empty file added src/webdav/mod.rs
Empty file.
24 changes: 24 additions & 0 deletions tests/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extern crate hyper;
extern crate hyperdav;
extern crate url;
extern crate uuid;

use hyper::status::StatusCode;
use hyperdav::Client;
use url::Url;

macro_rules! url {
($e:expr) => (Url::parse(&format!("https://test:test@demo.owncloud.org/remote.php/webdav/{}", $e)).unwrap());
}

macro_rules! random_url {
() => (url!(uuid::Uuid::new_v4()));
}

#[test]
fn put() {
let client = Client::new();
let mut f = std::io::empty();
let res = client.put(&mut f, random_url!()).send().unwrap();
assert_eq!(res.status, StatusCode::Created);
}

0 comments on commit a37d50b

Please sign in to comment.