-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Metaswitch/master
catchup merge
- Loading branch information
Showing
16 changed files
with
1,247 additions
and
203 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
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
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,15 @@ | ||
# Contributing to `swagger-rs` | ||
|
||
Thanks for your interest - we gratefully welcome contributions. | ||
|
||
Questions can be asked in [issues](https://github.com/Metaswitch/swagger-rs/issues). | ||
|
||
To help us help you get pull requests merged quickly and smoothly, open an issue before submitted large changes. Please keep the contents of pull requests and commits short. Commit messages should include the intent of the commit. Pull requests should add an entry to [CHANGELOG.md]. | ||
|
||
Contributions that add/improve tests are awesome. Please add tests for every change. | ||
|
||
`swagger-rs` uses [`rustfmt-nightly`](https://github.com/rust-lang-nursery/rustfmt) for formatting and [`clippy`](https://github.com/rust-lang-nursery/rust-clippy) for linting. | ||
|
||
## Conduct | ||
|
||
In all `swagger-rs`-related forums, we follow the [Swagger Codegen Code of Conduct](https://github.com/swagger-api/swagger-codegen/blob/master/CODE_OF_CONDUCT.md). For escalation or moderation issues please contact Benjamin (mailto:[email protected]) instead of the swagger-api moderation team. |
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
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
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,15 @@ | ||
#!/usr/bin/env bash | ||
# Updated the changelog for a new release | ||
set -eou pipefail | ||
|
||
version=$1 | ||
date=$(date +%Y-%m-%d) | ||
|
||
|
||
sed -i "s/^version = \".\+\"$/version = \"$version\"/" Cargo.toml | ||
|
||
sed -i "s/## \[Unreleased\]/## [Unreleased]\n### Added\n\n### Changed\n\n### Removed\n\n## [$version] - $date/" CHANGELOG.md | ||
|
||
sed -i "s#\[Unreleased\]: https://github.com/Metaswitch/swagger-rs/compare/\(.*\)...HEAD#[Unreleased]: https://github.com/Metaswitch/swagger-rs/compare/$version...HEAD\n[$version]: https://github.com/Metaswitch/swagger-rs/compare/\1...$version#" CHANGELOG.md | ||
|
||
echo "Now, delete any empty headers from $version in CHANGELOG.md" |
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,69 @@ | ||
//! Hyper service that adds a context to an incoming request and passes it on | ||
//! to a wrapped service. | ||
use super::{Push, XSpanIdString}; | ||
use hyper; | ||
use hyper::{Error, Request, Response}; | ||
use std::io; | ||
use std::marker::PhantomData; | ||
|
||
/// Middleware wrapper service, that should be used as the outermost layer in a | ||
/// stack of hyper services. Adds a context to a plain `hyper::Request` that can be | ||
/// used by subsequent layers in the stack. | ||
#[derive(Debug)] | ||
pub struct AddContext<T, C> | ||
where | ||
C: Default + Push<XSpanIdString>, | ||
{ | ||
inner: T, | ||
marker: PhantomData<C>, | ||
} | ||
|
||
impl<T, C> AddContext<T, C> | ||
where | ||
C: Default + Push<XSpanIdString>, | ||
{ | ||
/// Create a new AddContext struct wrapping a value | ||
pub fn new(inner: T) -> Self { | ||
AddContext { | ||
inner, | ||
marker: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<T, C> hyper::server::NewService for AddContext<T, C> | ||
where | ||
C: Default + Push<XSpanIdString>, | ||
T: hyper::server::NewService< | ||
Request = (Request, C::Result), | ||
Response = Response, | ||
Error = Error, | ||
>, | ||
{ | ||
type Request = Request; | ||
type Response = Response; | ||
type Error = Error; | ||
type Instance = AddContext<T::Instance, C>; | ||
|
||
fn new_service(&self) -> Result<Self::Instance, io::Error> { | ||
self.inner.new_service().map(AddContext::new) | ||
} | ||
} | ||
|
||
impl<T, C> hyper::server::Service for AddContext<T, C> | ||
where | ||
C: Default + Push<XSpanIdString>, | ||
T: hyper::server::Service<Request = (Request, C::Result), Response = Response, Error = Error>, | ||
{ | ||
type Request = Request; | ||
type Response = Response; | ||
type Error = Error; | ||
type Future = T::Future; | ||
|
||
fn call(&self, req: Self::Request) -> Self::Future { | ||
let x_span_id = XSpanIdString::get_or_generate(&req); | ||
let context = C::default().push(x_span_id); | ||
self.inner.call((req, context)) | ||
} | ||
} |
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
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
Oops, something went wrong.