Commit graph

53 commits

Author SHA1 Message Date
Ashod Nakashian
aea70a563c wsd: http: disconnect if the server closed the socket
Change-Id: If00566939708d71482a8aac8e97cc371a4a381fd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-06 22:14:51 -04:00
Ashod Nakashian
a0696403a9 wsd: http: complete the http response only once
Change-Id: I2c015f004883272bb6efe4ffc5a14e3cc101f60f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-06 22:14:51 -04:00
Ashod Nakashian
a0549fd7cc wsd: http: simplify http::get
Change-Id: Id94d2e7340b393bd4a42f5108621f16b46a0ee9b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
117db770cd wsd: http: add isConnected getter to http::Session
Change-Id: Iad12f00f9ced434d4e1493aba03be98a3cd7f2ab
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
ea12aa7635 wsd: http: braces always on new line
Seems like this was a bug in clang-format
that is fixed in clang-12.

Change-Id: I8144179d2b290f5d875af41dbd44dedcf4152639
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-05-02 22:35:39 -04:00
Ashod Nakashian
dc5ca2738e wsd: http: simplify appending to Buffer
Instead of supporting char appending,
we now support appending literal strings
with size capturing. This covers both
single- and multi-character appending
without the need for an explicit size.

Change-Id: Iee2c20b7aa2cdb6863c88e91cd770205719c2ba6
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 96e3e88a014960a5249fc83a5b2f3b785ac8737d)
2021-05-02 22:35:39 -04:00
Miklos Vajna
656eb310bb Fix Debian 8 / gcc-4.9 warnings
net/HttpRequest.cpp:126:19: error: declaration of 'end' shadows a member of 'this' [-Werror=shadow]

kit/Kit.cpp:163:29: error: missing initializer for member 'statfs::f_bsize' [-Werror=missing-field-initializers]

kit/Kit.cpp:171:14: error: 'OVERLAYFS_SUPER_MAGIC' was not declared in this scope

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Ibbd35ab5af3adad403ed22a0aeb70917b9e21970
2021-04-30 10:38:09 +02:00
Ashod Nakashian
352840c0ea wsd: http: larger 64kb upload-file read buffer
Change-Id: Ie9a0e6f76425d796979dbc77eecf1b05993b834d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 34f629c6adc5bb6eb93fd8c813d72ee923d09a05)
2021-04-27 17:48:23 -04:00
Ashod Nakashian
3decba7eec wsd: specify the minimum bytes we can write to the socket
When writing to the socket, it's always more efficient
to fill the buffer up to the hardware limit for each
write. This is doubly important for efficiency with
SSL, due to the overhead of encrypting multiple
small buffers instead of one large one.

Currently we don't write more than one message
at a time, primarily due to limitations in
the Poco sockets in the unit-tests, which
have a hard time consuming multiple WS frames
with a single poll (subsequent calls to poll
doesn't enter signalled state until new data
arrives, possibly because the data is read and
buffered internally, making the whole scheme
of using poll unreliable and meaningless).

Change-Id: Ic2e2cf1babfb5ab4116efd93f392977ba234d92b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 17:48:23 -04:00
Miklos Vajna
9afe974848 Add a fuzzer for http::Response::readData()
And remove the httpheader one, which is not useful, since it uses Poco
for the actual parsing, it did not find anything. (If we switch away
from Poco there in the future, it's easy enough to restore it.)

Also fix some problems found by the fuzzer.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I254247c46ecc78c9c3e75aac4f10c441b0e10fb3
2021-04-23 17:54:36 +02:00
Ashod Nakashian
1239685620 wsd: http: explicit Request constructor and Header arg
Change-Id: Ief228862d882ae96650708e30442693cc127f0c9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
d9fa64b4a0 wsd: http: support http Connection: close header
According to the RFC, HTTP/1.1 assumes persistent
connection unless the client or server sends
'Connection: close' header. See
https://tools.ietf.org/html/rfc7230#section-6.3

Now we fully support disconnecting when we
get this header, which is important for when
reusing the same http::Session (we need to
reconnect in such a case).

Change-Id: Ib278eff21be32c1414478296e90e2e807ab24132
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
4b43b3cd6e wsd: http: set the port in the Host header entry
Change-Id: I2d46c1ef3b72e21ce8924dcf7616cd26fb5bc98d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
41275f0423 wsd: http: new syncRequest with timeout and new helper
Change-Id: I64a5d6f0984b9f35fe0224683527d80cf77fff99
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
2bb07adb54 wsd: http: simplify syncRequest to return Response
Since the return value of syncRequest and syncDownload
was derived from Response anyway, there is no reason
to have multiple values for callers to look at.

This simplifies the API.

Change-Id: I0f136e515dd0ef6eda84f6a7cd662b260809d2f1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
8aa329c17d wsd: http: default Session timeout is now public
Change-Id: I34376a68a130ccb0d36f04b90ff26af1a1535873
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
45b15803ad wsd: http: use std::move
Change-Id: I3c287b96ccce5f8b3cb245c065922a9c35df5bf7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
fb6e7793ff wsd: http: use parseUri
Change-Id: I5c1e95acb30509f2b1865da31a8a0e622a94c4e3
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
49a13798eb wsd: http: parse the host and validate
Change-Id: I3ad1bcf51d59295e411a949a714bb680ff789f34
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
6f8b6057b1 wsd: http: use std::move where sensible
Change-Id: Ie1c880224822f8c0b2db0e58dd83693335fbfd1f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00
Ashod Nakashian
f53e928530 wsd: http: support sending Request and Response in Socket
Improved handling of http::Request and http::Response
in Socket directly with better error handling and
automatic socket shutdown on error.

We shouldn't need to manually serialize into the
socket's buffer when sending a Request or Response.

Change-Id: I6dfcd2fe4f6b88cd2fa8c749045ce25a8c52fe9a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-03 19:57:03 -04:00
Ashod Nakashian
44b5314c8b wsd: http: don't process timeout if the request is done
Change-Id: If308c6e28cd7de7a70adbfd99f6f6623ff990e5d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:58:06 -04:00
Ashod Nakashian
560732e01b wsd: http: Response supports header getter and no Finished callback
Change-Id: I7ec7a021e7fdd1801a7ef7d1f44747178a1445c5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:58:06 -04:00
Ashod Nakashian
7f8ddf0079 wsd: http: support creating http::Session from URIs
A full URI with scheme can now be used to
create http::Session instances.

Change-Id: I3e556e3e1aa247ccb93749d9bd6736a15290f442
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:58:06 -04:00
Ashod Nakashian
0c48809593 wsd: http: Response writes out the body
It's now possible to set a body in http::Response
and it will get serialized out with the header.

Change-Id: If0f01a226bbd7b5ab092d0a246c8b46553a107e0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:58:06 -04:00
Ashod Nakashian
e3fa305896 wsd: http: get header entry with optional default
Change-Id: I6f11d9d39f3ba7b9e9907b3112f7317de3413071
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:58:06 -04:00
Ashod Nakashian
ac336419a2 wsd: http: comments and documentation
Change-Id: I3782e31d59c3664cade592b6b9d23a1ddf18f9ca
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:58:06 -04:00
Ashod Nakashian
5c6cd3aaec wsd: test: properly include config.h in the tests
When config.h is not included, the build
configuration is missing from the translation
unit in question. This affects ENABLE_SSL,
for one.

Also, HttpRequest.hpp depends on LOOLWSD_VERSION,
which is defined in config.h.

The config.h header must be included in all
trasnlation-units, and must be the first include.
This is to avoid conflicts and/or mismatching
binaries built with different compile-time values.

We also statically assert if LOOLWSD_VERSION
is not defined, to help the error message.

Change-Id: Ic4b45de879f3360a07e9507fdf04abfa4cec6a71
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 12:43:39 -04:00
Ashod Nakashian
1fd0f7302b wsd: http: make writeData const
Change-Id: I43b7abd737836873300b2195b6bb8b703cc3ec64
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
601b1cbd8b wsd: http: use std::move where efficient
Change-Id: Ic99ce8fd3508b496d544ac9a1459853f985165b7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
0c9283a7ae wsd: http: set date and server/agent as early as possible
Change-Id: I2856d7502f63e04138e2d615347f343280690b42
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
725a3070c3 wsd: tolerate missing FinishedCallback in http::Response
And explain the use of linear search in header().

Change-Id: If6c39bffa738861d0c86684f9560ed6e4a6970e1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
f494c27024 wsd: correct User-Agent usage in http headers
User-Agent is designed for client-side use only,
in http requests. For servers, the Server header
is designed to announce the server name and version.

This tries to normalize the use and documents
the proper intent and usage.

Change-Id: I42d68d65611cab64c45adf03fe74f9466798b093
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
4bda1ff1d1 wsd: http: use writeData to serialize http::Request
Change-Id: Ib67f92c34d42d7cdb922cbfc47222040a6deb603
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
de0358198c wsd: http: better serialization into the socket buffer directly
This adds writeData() member to write into the output
buffer of the socket directly, instead of serializing
into a string and then copying it over to the buffer.

Change-Id: I42aaa23e96a6120c738bc0bb36bc01f4ed5e70c5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
5749d7457d wsd: http: improve StatusLine
And update unit-tests.

Change-Id: I29bcb8232c77d3c0c1fe316854417726671765f1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
b13b1e85ce wsd: http: log the hostname in warning
Change-Id: I3aa5e134002aafe2e0090e87f9e275130983450f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
58d9bcd685 wsd: http: map Status Codes to Reason Phrases
Change-Id: I96c953950a865fe35a17540889e4cc75c84870b1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
b6314a6165 wsd: http: tolerate the absence of a reason phrase
Here we are more tolerant with regards to the
minimum Status Line length, since a Reason
Phrase is informative and might be omitted.

While technically it should be provided, per
the RFC, we shouldn't break when it's missing.

Change-Id: Ic702db61e5bf4272e18f09d127405033277e5943
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-22 10:09:22 -04:00
Ashod Nakashian
419e238fb7 wsd: http: better logging
Change-Id: Ic0dfe08564a1a5dd3fea5fcac93eadb21e7cb0dc
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-16 08:27:46 -04:00
Ashod Nakashian
ea9c483a28 wsd: http: StatusLine tests
Change-Id: Iac39191b407463d2691ec3c58af2a4b4abfc6645
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-16 08:27:46 -04:00
Ashod Nakashian
7c0851c4d4 wsd: http: support setting header fields from Request
Change-Id: I3483e20c1f54c15dbd7088f7bdb866abb7b99cf6
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-16 08:27:46 -04:00
Ashod Nakashian
688fefcbda wsd: http: define streaming operators
Change-Id: I911951cb29fe22103076af9f082e3a6eae3c6189
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-16 08:27:46 -04:00
Ashod Nakashian
78fe04a58d wsd: better http poll thread name
Change-Id: I60a4ee09fcfb1bd34b44a21253ecac78f3d6830f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-16 08:27:46 -04:00
Ashod Nakashian
774afe1393 wsd: http::Request parser
This adds support to parse client request
on the server side.

Unit-tests included.

Change-Id: I90e9ad3007a3215682991fd2383362e1c48589a8
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-16 08:27:46 -04:00
Ashod Nakashian
2281ace984 wsd: http: better logging and tracing
Change-Id: Ib7ba0c2bbf0228d816403408289bdbaf52a14458
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-16 08:27:46 -04:00
Ashod Nakashian
30fe875419 wsd: better http::Session::create API
Change-Id: I8d89bfc3ed482b775029ef23527e02f379051796
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-11 09:15:40 -05:00
Ashod Nakashian
26b7e43ecb wsd: comment typos
Change-Id: I4789899ac58c3c07c66b47d1945b04a5029e7b56
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-11 09:15:40 -05:00
Ashod Nakashian
561a9ce991 wsd: storage: upload to storage using http::Request
This converts Poco to http::Request in sync mode,
thereby not changing functionality. In a follow-up,
this will be converted to async.

Change-Id: Ifbecd44ff599394799c1131470d77f803ed8cc45
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-02-27 08:57:25 -05:00
Ashod Nakashian
b0b1d9ef3d wsd: fail when trying to connect to an invalid host
Change-Id: I3fb1a625a5e88fbbf5726034559207684f2851f2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-02-22 14:24:36 -05:00