Skip to content

Commit 5ed615d

Browse files
authored
Merge pull request #30 from gren-lang/fix-http-server-request-url
Fix incoming url parsing in HttpServer.Request
2 parents 961451d + 1a2e3cb commit 5ed615d

File tree

2 files changed

+14
-39
lines changed

2 files changed

+14
-39
lines changed

src/Gren/Kernel/HttpServer.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ var _HttpServer_addListener = F3(function (server, router, msg) {
4040
.on("end", function () {
4141
const buffer = Buffer.concat(body);
4242
let grenRequest = __HttpServer_toRequest({
43-
__$urlProtocol: url.protocol,
44-
__$urlHost: url.hostname,
45-
__$urlPort: url.port,
46-
__$urlPath: url.pathname,
47-
__$urlQuery: url.search,
48-
__$urlFragment: url.hash,
43+
__$url: url.href,
4944
__$headers: request.rawHeaders,
5045
__$method: request.method,
5146
__$body: new DataView(

src/HttpServer.gren

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -162,54 +162,34 @@ methodToString method =
162162
This is only used internally.
163163
-}
164164
toRequest :
165-
{ urlProtocol : String
166-
, urlHost : String
167-
, urlPort : String
168-
, urlPath : String
169-
, urlQuery : String
170-
, urlFragment : String
165+
{ url : String
171166
, headers : Array String
172167
, method : String
173168
, body : Bytes
174169
}
175170
-> Request
176171
toRequest
177-
{ urlProtocol
178-
, urlHost
179-
, urlPort
180-
, urlPath
181-
, urlQuery
182-
, urlFragment
172+
{ url
183173
, headers
184174
, method
185175
, body
186176
} =
187177
{ method = toMethod method
188178
, body = body
179+
, url =
180+
Url.fromString url
181+
|> Maybe.withDefault
182+
{ protocol = Http
183+
, port_ = Nothing
184+
, host = ""
185+
, path = ""
186+
, query = Nothing
187+
, fragment = Nothing
188+
}
189189
, headers =
190190
headers
191191
|> arrayPairs
192192
|> dictFromPairs
193-
, url =
194-
{ protocol =
195-
if urlProtocol == "https:" then
196-
Https
197-
else
198-
Http
199-
, host = urlHost
200-
, path = urlPath
201-
, port_ = String.toInt urlPort
202-
, query =
203-
if urlQuery == "" then
204-
Nothing
205-
else
206-
Just urlQuery
207-
, fragment =
208-
if urlFragment == "" then
209-
Nothing
210-
else
211-
Just urlFragment
212-
}
213193
}
214194

215195

@@ -266,7 +246,7 @@ requestInfo req =
266246
UNKNOWN m ->
267247
"UNKNOWN(" ++ m ++ ")"
268248
in
269-
method ++ " " ++ req.url.path
249+
method ++ " " ++ (Url.toString req.url)
270250

271251

272252
toMethod : String -> Method

0 commit comments

Comments
 (0)