Skip to content

Commit 2dadd7d

Browse files
committed
http/h1_{connection,stream}: use 'target' instead of 'path' for request line
1 parent 1f30846 commit 2dadd7d

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

doc/modules/http.h1_connection.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Used to hand the reference of the connection socket to another object. Resets th
113113

114114
### `h1_connection:read_request_line(timeout)` <!-- --> {#http.h1_connection:read_request_line}
115115

116-
Reads a request line from the socket. Returns the request method, requested path and HTTP version for an incoming request. `:read_request_line()` yields until a `"\r\n"` terminated chunk is received, or `timeout` is exceeded. If the incoming chunk is not a valid HTTP request line, `nil` is returned. On error, returns `nil`, an error message and an error number.
116+
Reads a request line from the socket. Returns the request method, request target and HTTP version for an incoming request. `:read_request_line()` yields until a `"\r\n"` terminated chunk is received, or `timeout` is exceeded. If the incoming chunk is not a valid HTTP request line, `nil` is returned. On error, returns `nil`, an error message and an error number.
117117

118118

119119
### `h1_connection:read_status_line(timeout)` <!-- --> {#http.h1_connection:read_status_line}
@@ -146,7 +146,7 @@ Reads the entire request body. This function will yield until the body is comple
146146
Reads the next available line of data from the request and returns the chunk and any chunk extensions. This function will yield until chunk size is received or `timeout` is exceeded. If the chunk size is indicated as `0` then `false` and any chunk extensions are returned. Returns `nil`, an error message and an error number if there was an error reading reading the chunk header or the socket.
147147

148148

149-
### `h1_connection:write_request_line(method, path, httpversion, timeout)` <!-- --> {#http.h1_connection:write_request_line}
149+
### `h1_connection:write_request_line(method, target, httpversion, timeout)` <!-- --> {#http.h1_connection:write_request_line}
150150

151151
Writes the opening HTTP 1.x request line for a new request to the socket buffer. Yields until success or `timeout`. If the write fails, returns `nil`, an error message and an error number.
152152

http/h1_connection.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function connection_methods:read_request_line(timeout)
167167
end
168168
return nil, err, errno
169169
end
170-
local method, path, httpversion = line:match("^(%w+) (%S+) HTTP/(1%.[01])\r\n$")
170+
local method, target, httpversion = line:match("^(%w+) (%S+) HTTP/(1%.[01])\r\n$")
171171
if not method then
172172
self.socket:seterror("r", ce.EILSEQ)
173173
local ok, errno2 = self.socket:unget(line)
@@ -183,7 +183,7 @@ function connection_methods:read_request_line(timeout)
183183
return nil, onerror(self.socket, "read_request_line", ce.EILSEQ)
184184
end
185185
httpversion = httpversion == "1.0" and 1.0 or 1.1 -- Avoid tonumber() due to locale issues
186-
return method, path, httpversion
186+
return method, target, httpversion
187187
end
188188

189189
function connection_methods:read_status_line(timeout)
@@ -344,11 +344,11 @@ function connection_methods:read_body_chunk(timeout)
344344
end
345345
end
346346

347-
function connection_methods:write_request_line(method, path, httpversion, timeout)
347+
function connection_methods:write_request_line(method, target, httpversion, timeout)
348348
assert(method:match("^[^ \r\n]+$"))
349-
assert(path:match("^[^ \r\n]+$"))
349+
assert(target:match("^[^ \r\n]+$"))
350350
assert(httpversion == 1.0 or httpversion == 1.1)
351-
local line = string.format("%s %s HTTP/%s\r\n", method, path, httpversion == 1.0 and "1.0" or "1.1")
351+
local line = string.format("%s %s HTTP/%s\r\n", method, target, httpversion == 1.0 and "1.0" or "1.1")
352352
local ok, err, errno = self.socket:xwrite(line, "f", timeout)
353353
if not ok then
354354
return nil, err, errno

http/h1_stream.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,24 +267,24 @@ function stream_methods:read_headers(timeout)
267267
if self.state == "half closed (local)" then
268268
return nil
269269
end
270-
local method, path, httpversion = self.connection:read_request_line(0)
270+
local method, target, httpversion = self.connection:read_request_line(0)
271271
if method == nil then
272272
if httpversion == ce.ETIMEDOUT then
273273
timeout = deadline and deadline-monotime()
274274
if cqueues.poll(self.connection.socket, timeout) ~= timeout then
275275
return self:read_headers(deadline and deadline-monotime())
276276
end
277277
end
278-
return nil, path, httpversion
278+
return nil, target, httpversion
279279
end
280280
self.req_method = method
281281
self.peer_version = httpversion
282282
headers = new_headers()
283283
headers:append(":method", method)
284284
if method == "CONNECT" then
285-
headers:append(":authority", path)
285+
headers:append(":authority", target)
286286
else
287-
headers:append(":path", path)
287+
headers:append(":path", target)
288288
end
289289
headers:append(":scheme", self:checktls() and "https" or "http")
290290
self:set_state("open")
@@ -564,14 +564,14 @@ function stream_methods:write_headers(headers, end_stream, timeout)
564564
if self.state == "idle" then
565565
method = assert(headers:get(":method"), "missing method")
566566
self.req_method = method
567-
local path
567+
local target
568568
if method == "CONNECT" then
569-
path = assert(headers:get(":authority"), "missing authority")
569+
target = assert(headers:get(":authority"), "missing authority")
570570
assert(not headers:has(":path"), "CONNECT requests should not have a path")
571571
else
572572
-- RFC 7230 Section 5.4: A client MUST send a Host header field in all HTTP/1.1 request messages.
573573
assert(self.connection.version < 1.1 or headers:has(":authority"), "missing authority")
574-
path = assert(headers:get(":path"), "missing path")
574+
target = assert(headers:get(":path"), "missing path")
575575
end
576576
if self.connection.req_locked then
577577
-- Wait until previous request has been fully written
@@ -585,7 +585,7 @@ function stream_methods:write_headers(headers, end_stream, timeout)
585585
self.connection.pipeline:push(self)
586586
self.connection.req_locked = self
587587
-- write request line
588-
local ok, err, errno = self.connection:write_request_line(method, path, self.connection.version, 0)
588+
local ok, err, errno = self.connection:write_request_line(method, target, self.connection.version, 0)
589589
if not ok then
590590
return nil, err, errno
591591
end

0 commit comments

Comments
 (0)