Skip to content

Commit

Permalink
## 0.4.0
Browse files Browse the repository at this point in the history
### User-impacting

- Fix: Non-GET requests may have been problematic
- Enhancement: Allow POST body
  • Loading branch information
brettz9 committed Jun 18, 2021
1 parent 88e0c70 commit 2c3ff5d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGES for client-tell

## 0.4.0

### User-impacting

- Fix: Non-GET requests may have been problematic
- Enhancement: Allow POST body

## 0.3.0

### User-impacting
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function post (e) {
url: 'retrieve.js',
body: {
url,
postData: $('#postData').value,
method: $('#method').value,
headers: [...$('table.requestHeaders').rows].slice(1).reduce((h, row) => {
const {cells} = row;
Expand Down Expand Up @@ -101,6 +102,12 @@ jml('div', {className: 'ancestor'}, [
['label', {className: 'col'}, [
['div', {className: 'urlCol'}, ['URL ']],
['input', {className: 'urlCol', type: 'url', $on: {change: post}}],
['div', [
['label', [
'Post body',
['textarea', {id: 'postData', style: 'height: 100px; width: 100%;'}]
]]
]],
['div', [
['label', [
'HTTP Method: ',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "client-tell",
"version": "0.3.0",
"version": "0.4.0",
"description": "HTTP client app in HTML/Node",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const retrieveURLAndHeaders = async function (req, res) {
}
});
const urlObj = new URL(requestedInfo.url);
const {method} = requestedInfo;
const {method, postData} = requestedInfo;

const opts = {
hostname: urlObj.hostname,
Expand All @@ -90,7 +90,7 @@ const retrieveURLAndHeaders = async function (req, res) {
headers: requestedInfo.headers
};
const protocol = urlObj.protocol === 'https:' ? https : http;
const rq = protocol.get(opts, async (resp) => {
const rq = protocol.request(opts, async (resp) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);

Expand All @@ -103,6 +103,10 @@ const retrieveURLAndHeaders = async function (req, res) {
rq.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
});
if (postData) {
rq.write(postData);
}
rq.end();
};

http.createServer((req, res) => {
Expand Down

0 comments on commit 2c3ff5d

Please sign in to comment.