Skip to content

Commit

Permalink
🐛 Fix Conduit#parseUrl() not being able to parse the host & protoco…
Browse files Browse the repository at this point in the history
…l of http2 requests
  • Loading branch information
skerit committed Oct 18, 2023
1 parent e2ee2fa commit 72ce602
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.19 (WIP)

* Fix `Conduit#parseUrl()` not being able to parse the host & protocol of http2 requests

## 1.3.18 (2023-10-17)

* Add `Alchemy#setMaxEventLoopLag(max_lag)` method
Expand Down
22 changes: 11 additions & 11 deletions lib/class/conduit.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,11 @@ Conduit.setMethod(async function parseRequest() {
});

/**
* Parse the url if it hasn't been done already
* Parse the complete request URL if it hasn't been done yet
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 1.3.18
* @version 1.3.18
* @version 1.3.19
*/
Conduit.setMethod(function parseUrl() {

Expand All @@ -569,6 +569,8 @@ Conduit.setMethod(function parseUrl() {
protocol = 'https://';
} else if (this.headers['x-forwarded-proto']) {
protocol = this.headers['x-forwarded-proto'];
} else if (this.headers[':scheme']) {
protocol = this.headers[':scheme'];
} else if (this.protocol) {
protocol = this.protocol;
} else if (this.encrypted) {
Expand All @@ -583,21 +585,19 @@ Conduit.setMethod(function parseUrl() {
// Set the protocol
this.url.protocol = protocol;

// Get the host/domain/authority of the request
const host = this.headers[':authority'] || this.headers.host;

// Set the host
this.url.hostname = this.headers.host;
this.url.hostname = host;

// If no URL was set, use the first requests URL (without the path)
if (!alchemy.settings.url && this.headers.host) {
if (!alchemy.settings.url && host) {
alchemy.setUrl(this.url);
}

let path = this.original_path;

if (this.prefix) {
path = '/' + this.prefix + '/' + path;
}

this.url.path = path;
// Set the entire original path
this.url.path = this.original_path;

return true;
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alchemymvc",
"description": "MVC framework for Node.js",
"version": "1.3.18",
"version": "1.3.19-alpha",
"author": "Jelle De Loecker <jelle@elevenways.be>",
"keywords": [
"alchemy",
Expand Down

0 comments on commit 72ce602

Please sign in to comment.