-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a37d50b
Showing
8 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |