Commit graph

603 commits

Author SHA1 Message Date
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
9d5f8fc73e wsd: http: improved parseUri and new parseUrl with tests
Change-Id: Icee821ab6176d17e08bfc6bc581eaf4b3986da60
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
abc4423997 wsd: add utility to connect to socket given a uri
Change-Id: I2ec9497c2392f9f246a461b052802a7b85d3eb13
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:58:06 -04:00
Ashod Nakashian
c80e31ed31 wsd: trace socket data
Change-Id: Idb86e4ba86342e7f9993abc644af06a0dbd83dd7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:58:06 -04:00
Ashod Nakashian
d382282f42 wsd: log socket data only in debug builds
Change-Id: I4072f431a353327808e21bcbd9de89745fb8bfa2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:58:06 -04:00
Ashod Nakashian
61670a6e8a wsd: better support for erasing from the socket in-buffer
We shouldn't need to erase from the in-buffer manually
anywhere. This utility encapsulates this functionality
well and protects against off-by-one errors.

Change-Id: I53616444ac9811a1e22d23d96a9cac8965b8518b
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
88dbe155e4 wsd: http: support sending http::Response directly to the socket
The Socket now accepts http::Response and
serializes it before sending it.

Change-Id: Id36e2d91b21d168da72ccdbd7e509ec08021b78e
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
e9c5c0f812 wsd: add utility to parse URIs into primary components
With unit-tests.

Change-Id: Ie6ae1a4fee4863e27ea90af1cf476a72300fa10e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:18:41 -04:00
Ashod Nakashian
23cde8454a wsd: more informative SSL state reporting
Change-Id: Icd4b05e0190f1ae581cbe1b4e7df87bb439a63c8
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:18:41 -04:00
Ashod Nakashian
54a10729f3 killpoco: replace Poco::icompare
Change-Id: I9b8154538c85593f054afd17bd588a593b803e98
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-02 13:18:41 -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
b3f8657550 wsd: use http::Response to parse client websocket upgrade
Change-Id: I9e869fa22c7696f7ee903770579abe5f4e03d4fc
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
69436ed0f3 wsd: const correctness
Change-Id: I14118245e77d796ad494d5e576d2e2c593f6d742
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
40b1aa1077 wsd: add member to Socket to flush safely
In many cases we write directly to the socket
outgoing buffer directly. The only way to flush
this buffer to the socket is to use send(),
which is artificial if we don't have any more
data to pass to send().

This makes it possible to safely call flush()
and, if there is buffered data, we flush it
to the socket.

Change-Id: I025e7ba5d1898e72dd0001547e104642608ab20a
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
1f978d9b50 wsd: cleanup Poco headers
Change-Id: I1eec2301576fc2f1cde40389b1f858f80b1204c0
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
da07625352 wsd: http: parse the http header only
Previously, we were parsing the Status Line
and the header, both together. This of course
doesn't work when we had removed the Status
Line already. This wasn't an issue in parsing
responses from servers, but doesn't work when
parsing requests from clients (i.e. in a server).

Also, it's simpler.

Tests extended accordingly.

Change-Id: Id1c9a6385080c86b6072130fa8a169a699c42462
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
c38e876978 wsd: minor logging improvement
Change-Id: I2fda8c023592396a937a02903e7c5260c6ccdd25
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
77fb416c40 wsd: http: normalize helper function API
Change-Id: I5070dd53fb6d5e38d851cb9f521f63b59353b778
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-16 08:27:46 -04:00
Ashod Nakashian
df0ce9cc42 wsd: http: factor out whitespace check
Change-Id: Ib078b0a587ff4fd91c0d48e79e9e75b8fcc31939
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-03-16 08:27:46 -04:00