Skip to content

Commit

Permalink
Merge branch 'release/0.8.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed Jan 28, 2019
2 parents 91a1bc7 + 92c9042 commit 37f0df8
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 17 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## [0.8.4] - 2019-01-28
### Fixed
* Fix not to pass "undefined" if content-type in multipart is not present
### Added
* Add a functionality of text input in web client

## [0.8.3] - 2019-01-25
### Added
* Pass the sender's headers in multipart
Expand Down Expand Up @@ -107,7 +113,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
* Docker automated build on Docker Hub
* Support HTTPS

[Unreleased]: https://github.com/nwtgck/piping-server/compare/v0.8.3...HEAD
[Unreleased]: https://github.com/nwtgck/piping-server/compare/v0.8.4...HEAD
[0.8.4]: https://github.com/nwtgck/piping-seraver/compare/v0.8.3...v0.8.4
[0.8.3]: https://github.com/nwtgck/piping-seraver/compare/v0.8.2...v0.8.3
[0.8.2]: https://github.com/nwtgck/piping-seraver/compare/v0.8.1...v0.8.2
[0.8.1]: https://github.com/nwtgck/piping-seraver/compare/v0.8.0...v0.8.1
Expand Down
19 changes: 13 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "piping-server",
"version": "0.8.3",
"version": "0.8.4",
"description": "HTTP Piping Data Transfer Server",
"bin": {
"piping-server": "dist/src/index.js"
Expand Down
59 changes: 50 additions & 9 deletions src/piping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ const indexPage: string =
<h1>Piping</h1>
Streaming file sending/receiving
<form method="POST" id="file_form" enctype="multipart/form-data">
<h3>Step 1: Choose a file</h3>
<input type="file" name="input_file"><br>
<h3>Step 1: Choose a file or text</h3>
<input type="checkbox" id="inputMode" onchange="toggleInputMode()">: <b>Text mode</b><br><br>
<input type="file" name="input_file">
<textarea type="text" name="input_text" placeholder="Input text" cols="30" rows="10"></textarea>
<br>
<h3>Step 2: Write your secret path</h3>
(e.g. "abcd1234", "mysecret.png?n=3")<br>
<input id="secret_path" placeholder="Secret path" size="50"><br>
Expand All @@ -106,14 +112,46 @@ const indexPage: string =
https://github.com/nwtgck/piping-server#readme
</a><br>
<script>
var fileForm = document.getElementById("file_form");
var secretPathInput = document.getElementById("secret_path");
secretPathInput.onkeyup = function(){
fileForm.action = "/" + secretPathInput.value;
};
// Set secret path action routing
(function () {
var fileForm = document.getElementById("file_form");
var secretPathInput = document.getElementById("secret_path");
secretPathInput.onkeyup = function(){
fileForm.action = "/" + secretPathInput.value;
};
})();
// Toggle input mode: file or text
var toggleInputMode = (function () {
var fileInput = document.getElementsByName("input_file")[0];
var textInput = document.getElementsByName("input_text")[0];
var activeInput = fileInput;
var deactivatedInput = textInput;
// Set inputs' functionality and visibility
function setInputs() {
activeInput.disabled = false;
activeInput.style.display = null;
deactivatedInput.disabled = true;
deactivatedInput.style.display = "none";
}
setInputs();
// Body of toggleInputMode
function toggle() {
// Swap inputs
var tmpInput = activeInput;
activeInput = deactivatedInput;
deactivatedInput = tmpInput;
setInputs();
}
return toggle;
})();
</script>
</body>
</html>`;
</html>
`;

/**
* Generate help page
Expand Down Expand Up @@ -304,7 +342,10 @@ export class Server {
part.byteCount === undefined ?
{} : {"Content-Length": part.byteCount}
),
"Content-Type": part.headers["content-type"]
...(
part.headers["content-type"] === undefined ?
{} : {"Content-Type": part.headers["content-type"]}
)
};

// Write headers to a receiver
Expand Down
40 changes: 40 additions & 0 deletions test/piping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,4 +675,44 @@ describe("piping.Server", () => {
});
});

context("By multipart/data-form", () => {
it("should allow sender to send data via multipart without multipart content-type", async () => {
const formData = {
"dummy form name": "this is a content"
};

// Send data
request.post({url: `${pipingUrl}/mydataid`, formData: formData});

await sleep(10);

const getPromise1 = thenRequest("GET", `${pipingUrl}/mydataid`);

const getData1 = await getPromise1;
assert.equal(getData1.statusCode, 200);
assert.equal(getData1.getBody("UTF-8"), "this is a content");
});

it("should pass sender's Content-Type to receivers' one", async () => {
const formData = {
"dummy form name": {
value: "this is a content",
options: {
contentType: "text/plain"
}
}
};

// Send data
request.post({url: `${pipingUrl}/mydataid`, formData: formData});

await sleep(10);

const getPromise1 = thenRequest("GET", `${pipingUrl}/mydataid`);

const getData1 = await getPromise1;
assert.equal(getData1.statusCode, 200);
assert.equal(getData1.headers["content-type"], "text/plain");
});
});
});

0 comments on commit 37f0df8

Please sign in to comment.