Commit Graph

41 Commits

Author SHA1 Message Date
Ali Mohammad Pur
5b185d9cb5 LibHTTP: Bump max HTTP header size up to 32KiB
Apparently discord likes to feed us headers as big as 6KiB, so clearly
there are large headers out there in the wild.
For reference, Apache's limit is 8KiB, and IIS's limit is 16KiB (this
limit is not defined by the spec, so nothing can stop a server from
sending massive headers - sadly)
2021-10-04 18:26:16 +02:00
Ali Mohammad Pur
64e231bd38 LibHTTP+LibGemini: Set underlying sockets as idle when detaching
This ultimately makes the sockets not spin while unused (particularly in
the 10s shutdown period that RequestServer's cache has).
2021-10-04 15:31:26 +02:00
Ali Mohammad Pur
830b0e8f2d LibHTTP: Treat EOF on a non-Finished state as an error 2021-10-04 15:31:26 +02:00
Ali Mohammad Pur
fdd2d49c5b LibHTTP: Ignore empty reads on chunk boundaries 2021-10-04 13:06:03 +02:00
Ali Mohammad Pur
3564e4eff1 LibHTTP: Consider a job failed if its body fails decompression
Our previous behaviour of treating the original invalid compressed body
as the decompressed response is quite silly, if the headers and response
doesn't match up, the job has failed.
2021-10-04 13:06:03 +02:00
Ali Mohammad Pur
b0a9c5673e LibHTTP: Respect the 'Connection: close' header on keep-alive jobs
If the server responds with this header, we _must_ close the connection,
as the server is allowed to ignore the socket and not respond to
anything past that response.
Fixes some RequestServer spins.
2021-09-30 11:46:37 +02:00
Ali Mohammad Pur
436693c0c9 LibTLS: Use a setter for on_tls_ready_to_write with some more smarts
The callback should be called as soon as the connection is established,
and if we actually set the callback when it already is, we expect it to
be called immediately.
2021-09-19 21:10:23 +04:30
Ali Mohammad Pur
65f7e45a75 RequestServer+LibHTTP+LibGemini: Cache connections to the same host
This makes connections (particularly TLS-based ones) do the handshaking
stuff only once.
Currently the cache is configured to keep at most two connections evenly
balanced in queue size, and with a grace period of 10s after the last
queued job has finished (after which the connection will be dropped).
2021-09-19 21:10:23 +04:30
Ali Mohammad Pur
c5d7eb8618 LibHTTP: Exit the read loop early when there cannot be any further data 2021-09-19 21:10:23 +04:30
Idan Horowitz
d6cfa34667 AK: Make URL::m_port an Optional<u16>, Expose raw port getter
Our current way of signalling a missing port with m_port == 0 was
lacking, as 0 is a valid port number in URLs.
2021-09-14 00:14:45 +02:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
sin-ack
8ea22121ac Userland: Migrate to argument-less deferred_invoke
Only one place used this argument and it was to hold on to a strong ref
for the object. Since we already do that now, there's no need to keep
this argument around since this can be easily captured.

This commit contains no changes.
2021-09-02 03:47:47 +04:30
brapru
d456af1cd3 LibCore+LibHTTP: Check the status of the socket after EINPROGRESS
Previously the system would assume the socket was connected after the
file descriptor became writeable. Just because the fd is signaled as
ready for output does not necessarily indicate the socket is connected.
Instead, we should check the status of the socket with SO_ERROR and
handle successes/errors accordingly.
2021-08-13 20:30:19 +04:30
Ali Mohammad Pur
f4eab69785 LibHTTP: Finish the request up on TLS connection finish
...unless it has already been done.
Otherwise we'd be spinning in RequestServer waiting for more read
events.
2021-06-30 01:23:25 +04:30
Ali Mohammad Pur
3058ff1500 LibHTTP: Relax the finish_up() "must be called once" limitation a bit
It's alright for this function to be called multiple times, as it quits
early when a partial flush doesn't empty the download buffer.
Relax the assertion to having scheduled "did_finish()" only once.
2021-06-29 01:57:16 +04:30
Ali Mohammad Pur
55fa2329de LibHTTP: Ensure finish_up() is not called more than once
There's no reason to manually call it on TLS close, the HTTP reading
logic is smart enough to handle connection closes transparently.
Fixes #8211.
2021-06-28 16:35:04 +02:00
Max Wipfli
1d990b3e7b LibHTTP: Add HTTP Basic Authentication header generation and parsing
This patch adds two new static methods to HttpRequest.
get_http_basic_authentication_header generates a "Authorization" header
from a given URL, where as parse_http_basic_authentication_header parses
an "Authorization" header into username and password.
2021-06-11 11:37:15 +02:00
Max Wipfli
631faec32f LibHTTP: Implement getting the correct reason phrase from HttpResponse
This adds a reason_phrase() getter and a static reason_phrase_for_code()
to the HttpResponse class.

It also changes the class to use east const style.
2021-06-11 11:37:15 +02:00
Max Wipfli
ce80188d6f LibHTTP: Percent encode/decode request URI
This percent encodes/decodes the request URI when creating or parsing
raw HTTP requests. This is necessary because AK::URL now contains
percent decoded data, meaning we have to re-encode it for creating
raw requests.
2021-06-01 09:28:05 +02:00
Linus Groh
81b7b2f49e LibHTTP: Replace fprintf(stderr) with warnln() 2021-05-31 17:43:54 +01:00
Ali Mohammad Pur
a57f152ec7 LibHTTP: Relax the assertion on extra reads after transfer is finished
This was added in #4831, but it didn't account for extra newlines after
the response (seems like some servers like to do this).
2021-05-19 23:57:04 +02:00
Gunnar Beutner
f1dc8e12d2 LibHTTP: Make sure we're not sending an empty path in requests
When the path component of the request URL was empty we'd end up
sending requests like "GET  HTTP/1.1" (note the missing /). This
ensures that we always send a path.
2021-05-17 21:28:00 +02:00
Gunnar Beutner
53d0150827 AK+Userland: Remove nullability feature for the ByteBuffer type
Nobody seems to use this particular feature, in fact there were some
bugs which were uncovered by removing operator bool.
2021-05-16 17:49:42 +02:00
Ali Mohammad Pur
8419ddb4d8 RequestServer: Only attempt to flush() on a timer
...instead of doing so immediately.
This makes RequestServer not spin as much when its client isn't fast
enough to empty the download pipe.
It also has the nice benefit of allowing multiple downloads to happen
at the same time without one blocking the other too much.
2021-05-12 08:36:58 +01:00
Gunnar Beutner
6cf59b6ae9 Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr 2021-05-01 21:25:06 +02:00
Linus Groh
649d2faeab Everywhere: Use "the SerenityOS developers." in copyright headers
We had some inconsistencies before:

- Sometimes "The", sometimes "the"
- Sometimes trailing ".", sometimes no trailing "."

I picked the most common one (lowecase "the", trailing ".") and applied
it to all copyright headers.

By using the exact same string everywhere we can ensure nothing gets
missed during a global search (and replace), and that these
inconsistencies are not spread any further (as copyright headers are
commonly copied to new files).
2021-04-29 00:59:26 +02:00
Andreas Kling
b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
AnotherTest
339ae7873e LibHTTP: Trim the whitespace around the Transfer-Encoding header value
Fixes #6302.
2021-04-14 09:31:31 +02:00
AnotherTest
7c98a6be17 LibHTTP: Handle running out of input between chunk body and ending CRLF
Fixes an issue where LibHTTP would incorrectly detect an end of stream
when it runs out of TLS application data between the chunk body and its
ending CRLF.
2021-04-12 08:36:21 +02:00
Luke
6cad2aba5e LibHTTP: Add support for the deflate content encoding 2021-03-22 12:45:34 +01:00
Idan Horowitz
c12781a6a2 LibCore+LibHTTP+LibGfx: Switch to LibCompress
This commit removes the only 3rd party library (and its usages)
in serenity: puff, which is used for deflate decompression. and
replaces it with the existing original serenity implementation
in LibCompress. :^)
2021-03-03 23:42:32 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
AnotherTest
09a43969ba Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-02-08 18:08:55 +01:00
asynts
eea72b9b5c Everywhere: Hook up remaining debug macros to Debug.h. 2021-01-25 09:47:36 +01:00
asynts
8465683dcf Everywhere: Debug macros instead of constexpr.
This was done with the following script:

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/dbgln<debug_([a-z_]+)>/dbgln<\U\1_DEBUG>/' {} \;

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/if constexpr \(debug_([a-z0-9_]+)/if constexpr \(\U\1_DEBUG/' {} \;
2021-01-25 09:47:36 +01:00
asynts
acdcf59a33 Everywhere: Remove unnecessary debug comments.
It would be tempting to uncomment these statements, but that won't work
with the new changes.

This was done with the following commands:

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \;

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-25 09:47:36 +01:00
asynts
1a3a0836c0 Everywhere: Use CMake to generate AK/Debug.h.
This was done with the help of several scripts, I dump them here to
easily find them later:

    awk '/#ifdef/ { print "#cmakedefine01 "$2 }' AK/Debug.h.in

    for debug_macro in $(awk '/#ifdef/ { print $2 }' AK/Debug.h.in)
    do
        find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/#ifdef '$debug_macro'/#if '$debug_macro'/' {} \;
    done

    # Remember to remove WRAPPER_GERNERATOR_DEBUG from the list.
    awk '/#cmake/ { print "set("$2" ON)" }' AK/Debug.h.in
2021-01-25 09:47:36 +01:00
Luke
712f76c010 LibHTTP: Always read in the last chunk
This was accidentally put behind a debug flag.

Fixes #5080
2021-01-24 09:25:47 +01:00
asynts
6dc2c38fd0 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-22 22:14:30 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00