Skip to content

Commit d1a7243

Browse files
author
Diego Nehab
committedOct 13, 2007
New release.
1 parent 52ac60a commit d1a7243

File tree

9 files changed

+59
-37
lines changed

9 files changed

+59
-37
lines changed
 

‎NEW

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ What's New
22

33
This is just a bug-fix/update release.
44

5+
* Improved: http.request() now supports deprecated HTTP/0.9
6+
servers (Florian Berger)
7+
* Fixed: could return "timedout" instead of "timeout" (Leo Leo)
58
* Fixed: crash when reading '*a' on closed socket (Paul Ducklin);
69
* Fixed: return values are consistent when reading from closed sockets;
710
* Fixed: case sensitivity in headers of multipart messages in

‎TODO

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
replace \r\n with \0xD\0xA in everything
12
New mime support
23

3-
4-
54
ftp send should return server replies?
65
make sure there are no object files in the distribution tarball
76
http handling of 100-continue, see DB patch

‎doc/index.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ <h2 id=thanks>Special thanks</h2>
124124
David Burgess, who has helped push the library to a new level of quality and
125125
from whom I have learned a lot of stuff that doesn't show up in RFCs.
126126
Special thanks also to Carlos Cassino, who played a big part in the
127-
extensible design seen in the C core of LuaSocket 2.0. Recently, Mike Pall
127+
extensible design seen in the C core of LuaSocket 2.0. Mike Pall
128128
has been helping a lot too! Thanks to you all!
129129
</p>
130130

@@ -137,6 +137,9 @@ <h2 id=new>What's New</h2>
137137
</p>
138138

139139
<ul>
140+
<li> Improved: http.request() now supports deprecated
141+
HTTP/0.9 servers (Florian Berger);
142+
<li> Fixed: could return "timedout" instead of "timeout" (Leo Leo);
140143
<li> Fixed: crash when reading '*a' on closed socket (Paul Ducklin);
141144
<li> Fixed: return values are consistent when reading from closed sockets;
142145
<li> Fixed: case sensitivity in headers of multipart
@@ -195,7 +198,7 @@ <h2 id=old>Old Versions</h2>
195198
<p>
196199
<small>
197200
Last modified by Diego Nehab on <br>
198-
Thu Apr 20 00:25:23 EDT 2006
201+
Wed Oct 3 02:07:59 BRT 2007
199202
</small>
200203
</p>
201204
</center>

‎doc/tcp.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ <h2 id=tcp>TCP</h2>
284284
<li> '<tt>*l</tt>': reads a line of text from the socket. The line is
285285
terminated by a LF character (ASCII&nbsp;10), optionally preceded by a
286286
CR character (ASCII&nbsp;13). The CR and LF characters are not included in
287-
the returned line. This is the default pattern;
287+
the returned line. In fact, <em>all</em> CR characters are
288+
ignored by the pattern. This is the default pattern;
288289
<li> <tt>number</tt>: causes the method to read a specified <tt>number</tt>
289290
of bytes from the socket.
290291
</ul>

‎gem/TODO

-2
This file was deleted.

‎gem/ltn012.tex

+23-23
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ \section{Introduction}
6161

6262
\emph{Filters} are functions that can be repeatedly invoked
6363
with chunks of input, successively returning processed
64-
chunks of output. More importantly, the result of
64+
chunks of output. Naturally, the result of
6565
concatenating all the output chunks must be the same as the
6666
result of applying the filter to the concatenation of all
6767
input chunks. In fancier language, filters \emph{commute}
@@ -81,11 +81,12 @@ \section{Introduction}
8181
times along the way. Chains connect these nodes together.
8282
The initial and final nodes of the network are
8383
\emph{sources} and \emph{sinks}, respectively. Less
84-
abstractly, a source is a function that produces new data
85-
every time it is invoked. Conversely, sinks are functions
86-
that give a final destination to the data they receive.
87-
Naturally, sources and sinks can also be chained with
88-
filters to produce filtered sources and sinks.
84+
abstractly, a source is a function that produces new chunks
85+
of data every time it is invoked. Conversely, sinks are
86+
functions that give a final destination to the chunks of
87+
data they receive in sucessive calls. Naturally, sources
88+
and sinks can also be chained with filters to produce
89+
filtered sources and sinks.
8990

9091
Finally, filters, chains, sources, and sinks are all passive
9192
entities: they must be repeatedly invoked in order for
@@ -95,8 +96,8 @@ \section{Introduction}
9596

9697
In the following sections, we start with a simplified
9798
interface, which we later refine. The evolution we present
98-
is not contrived: it recreates the steps we followed
99-
ourselves as we consolidated our understanding of these
99+
is not contrived: it recreates the steps we ourselves
100+
followed as we consolidated our understanding of these
100101
concepts within our application domain.
101102

102103
\subsection{A simple example}
@@ -290,8 +291,8 @@ \subsection{The C part of the filter}
290291
\end{C}
291292
\end{quote}
292293

293-
When designing your own filters, the challenging part is to
294-
decide what will be in the context. For line breaking, for
294+
When designing filters, the challenging part is usually
295+
deciding what to store in the context. For line breaking, for
295296
instance, it could be the number of bytes that still fit in the
296297
current line. For Base64 encoding, it could be a string
297298
with the bytes that remain after the division of the input
@@ -408,8 +409,8 @@ \subsection{Filtered sources}
408409
Filtered sources are useful when working with
409410
functions that get their input data from a source (such as
410411
the pumps in our examples). By chaining a source with one or
411-
more filters, the function can be transparently provided
412-
with filtered data, with no need to change its interface.
412+
more filters, such functions can be transparently provided
413+
with filtered data, with no need to change their interfaces.
413414
Here is a factory that does the job:
414415
\begin{quote}
415416
\begin{lua}
@@ -434,11 +435,11 @@ \subsection{Filtered sources}
434435

435436
\subsection{Sinks}
436437

437-
Just as we defined an interface for source of data,
438-
we can also define an interface for a data destination.
439-
We call any function respecting this
440-
interface a \emph{sink}. In our first example, we used a
441-
file sink connected to the standard output.
438+
Just as we defined an interface for a source of data, we can
439+
also define an interface for a data destination. We call
440+
any function respecting this interface a sink. In our first
441+
example, we used a file sink connected to the standard
442+
output.
442443

443444
Sinks receive consecutive chunks of data, until the end of
444445
data is signaled by a \nil\ input chunk. A sink can be
@@ -665,7 +666,7 @@ \section{A complex example}
665666
with the server, and simply pumps the data. The message is never
666667
assembled in memory. Everything is produced on demand,
667668
transformed in small pieces, and sent to the server in chunks,
668-
including the file attachment that is loaded from disk and
669+
including the file attachment which is loaded from disk and
669670
encoded on the fly. It just works.
670671
671672
\section{Conclusions}
@@ -685,11 +686,10 @@ \section{Acknowledgements}
685686
The concepts described in this text are the result of long
686687
discussions with David Burgess. A version of this text has
687688
been released on-line as the Lua Technical Note 012, hence
688-
the name of the corresponding LuaSocket module,
689-
\texttt{ltn12}. Wim Couwenberg contributed to the
690-
implementation of the module, and Adrian Sietsma was the
691-
first to notice the correspondence between sources and Lua
692-
iterators.
689+
the name of the corresponding LuaSocket module, LTN12. Wim
690+
Couwenberg contributed to the implementation of the module,
691+
and Adrian Sietsma was the first to notice the
692+
correspondence between sources and Lua iterators.
693693
694694
695695
\end{document}

‎makefile.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ MAKE = \
8686
DOC = \
8787
doc/dns.html \
8888
doc/ftp.html \
89-
doc/home.html \
89+
doc/index.html \
9090
doc/http.html \
9191
doc/installation.html \
9292
doc/introduction.html \

‎src/http.lua

+23-5
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ function metat.__index:sendbody(headers, source, step)
142142
end
143143

144144
function metat.__index:receivestatusline()
145-
local status = self.try(self.c:receive())
145+
local status = self.try(self.c:receive(5))
146+
-- identify HTTP/0.9 responses, which do not contain a status line
147+
-- this is just a heuristic, but is what the RFC recommends
148+
if status ~= "HTTP/" then return nil, status end
149+
-- otherwise proceed reading a status line
150+
status = self.try(self.c:receive("*l", status))
146151
local code = socket.skip(2, string.find(status, "HTTP/%d*%.%d* (%d%d%d)"))
147152
return self.try(base.tonumber(code), status)
148153
end
@@ -163,6 +168,12 @@ function metat.__index:receivebody(headers, sink, step)
163168
sink, step))
164169
end
165170

171+
function metat.__index:receive09body(status, sink, step)
172+
local source = ltn12.source.rewind(socket.source("until-closed", self.c))
173+
source(status)
174+
return self.try(ltn12.pump.all(source, sink, step))
175+
end
176+
166177
function metat.__index:close()
167178
return self.c:close()
168179
end
@@ -271,6 +282,7 @@ function tredirect(reqt, location)
271282
create = reqt.create
272283
}
273284
-- pass location header back as a hint we redirected
285+
headers = headers or {}
274286
headers.location = headers.location or location
275287
return result, code, headers, status
276288
end
@@ -283,17 +295,23 @@ function trequest(reqt)
283295
-- send request line and headers
284296
h:sendrequestline(nreqt.method, nreqt.uri)
285297
h:sendheaders(nreqt.headers)
286-
local code = 100
287-
local headers, status
288-
-- if there is a body, check for server status
298+
-- if there is a body, send it
289299
if nreqt.source then
290300
h:sendbody(nreqt.headers, nreqt.source, nreqt.step)
291301
end
302+
local code, status = h:receivestatusline()
303+
-- if it is an HTTP/0.9 server, simply get the body and we are done
304+
if not code then
305+
h:receive09body(status, nreqt.sink, nreqt.step)
306+
return 1, 200
307+
end
308+
local headers
292309
-- ignore any 100-continue messages
293310
while code == 100 do
294-
code, status = h:receivestatusline()
295311
headers = h:receiveheaders()
312+
code, status = h:receivestatusline()
296313
end
314+
headers = h:receiveheaders()
297315
-- at this point we should have a honest reply from the server
298316
-- we can't redirect if we already used the source, so we report the error
299317
if shouldredirect(nreqt, code, headers) and not nreqt.source then

‎src/usocket.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ const char *socket_strerror(int err) {
359359
case ECONNREFUSED: return "connection refused";
360360
case ECONNABORTED: return "closed";
361361
case ECONNRESET: return "closed";
362-
case ETIMEDOUT: return "timedout";
362+
case ETIMEDOUT: return "timeout";
363363
default: return strerror(errno);
364364
}
365365
}

0 commit comments

Comments
 (0)
Please sign in to comment.