Commit Graph

493 Commits

Author SHA1 Message Date
Carl Lerche
e61788a57f Accept HPACK literals greater than max size (#244)
The spec specifically allows accepting HPACK literals with indexing when
the HPACK literal is greater than the max table size. In this case, the
literal is not inserted in the table.

Fixes #243
2018-03-22 12:58:23 -07:00
Darren Tsung
4595b54cfa Add initial_max_send_streams() as builder option (#242) 2018-03-16 11:58:06 -07:00
Carl Lerche
0cb3e648e9 Bump version to v0.1.2 (#239) 2018-03-13 18:11:11 -07:00
Carl Lerche
5d4c89b1a9 Fix client doc test (#241)
The test is not supposed to actually run, but the `select` is not fast
enough on Travis.
2018-03-13 14:53:35 -07:00
Darren Tsung
f8baeb7211 Streams receiving peer reset clear pending send (#238)
Because streams that were being peer reset were not clearing pending
send frames / buffered_send_data, they were not being counted towards
the concurrency limit.
2018-03-13 12:47:57 -07:00
Carl Lerche
70cf009305 Bump version to v0.1.1 (#236) 2018-03-08 10:06:40 -08:00
Carl Lerche
02841ebd77 Normalize HTTP request path. (#228)
The HTTP/2.0 specification requires that the path pseudo header is never
empty for requests unless the request uses the OPTIONS method.

This is currently not correctly enforced.

This patch provides a test and a fix.
2018-03-07 20:48:54 -08:00
Darren Tsung
bbed41974b Prevent pushing a stream into both pending_send + pending_open (#235)
Prevent pushing a stream into both pending_send + pending_open,
Clear out variables from buffered streams that get a reset, and
ignore them when traversing the pending_send queue if
they are is_reset(). Add asserts that a stream cannot be in
pending_open & pending_send at the same time.
2018-03-07 16:11:33 -08:00
Carl Lerche
dd0bb5b03e Add a comment explaining what pending_open is for (#232)
It isn't immediately obvious why the connection supports buffering
requests. The reason is that it models the futures' mpsc channel
behavior.

This patch adds a comment explaining this.
2018-03-07 13:48:20 -08:00
Sean McArthur
e3c6e0c590 Notify send_tasks when there is a connection error (#231) 2018-03-07 12:19:54 -08:00
Darren Tsung
ad90f9b97b Remove assert around self.pending_capacity.is_empty() (#225)
This assert does not hold as many streams can be pushed into
pending_capacity during a call to send_data(). See issue #224
for more discussion and sign-off.

Closes #224
2018-02-27 10:35:00 -08:00
Brian Smith
06672cbde9 Upgrade ordermap dependency to indexmap. (#227)
Avoid the need for indexmap-based applications to build ordermap,
which is the old name for indexmap.

Signed-off-by: Brian Smith <brian@briansmith.org>
2018-02-26 20:27:13 -08:00
Darren Tsung
0c59957d88 When Streams are dropped, close Connection (#221) (#222)
When all Streams are dropped / finished, the Connection was held
open until the peer hangs up. Instead, the Connection should hang up
once it knows that nothing more will be sent.

To fix this, we notify the Connection when a stream is no longer
referenced. On the Connection poll(), we check that there are no
active, held, reset streams or any references to the Streams
and transition to sending a GOAWAY if that is case.

The specific behavior depends on if running as a client or server.
2018-02-15 13:14:18 -08:00
walfie
73b4c03b55 Fix typos (#223) 2018-02-13 21:00:09 -08:00
Steven Fackler
ef99f99ae1 Fix documentation for end_of_stream (#219)
The END_STREAM flag is set when the stream is ending, so it needs to be
false if we're sending data.
2018-01-25 11:58:41 -08:00
Steven Fackler
9f4d463dba Update dependency spec (#217) 2018-01-12 11:48:10 -08:00
Carl Lerche
69bd8828ef Remove mock-io git dependency 2018-01-11 22:46:52 -08:00
Carl Lerche
78455a4496 Add docs for shared types (#216)
Add documentation for types shared between the client and server.
2018-01-11 15:00:16 -08:00
Carl Lerche
5604372a8b Client documentation (#212)
Add documentation for client APIs.
2018-01-11 13:55:51 -08:00
Carl Lerche
1db3f34de8 Implement SendRequest::ready. (#215)
This provides a functional future API for waiting for SendRequest
readiness.
2018-01-11 10:21:23 -08:00
Sean McArthur
aa23a9735d SETTINGS_MAX_HEADER_LIST_SIZE (#206)
This, uh, grew into something far bigger than expected, but it turns out, all of it was needed to eventually support this correctly.

- Adds configuration to client and server to set [SETTINGS_MAX_HEADER_LIST_SIZE](http://httpwg.org/specs/rfc7540.html#SETTINGS_MAX_HEADER_LIST_SIZE)
- If not set, a "sane default" of 16 MB is used (taken from golang's http2)
- Decoding header blocks now happens as they are received, instead of buffering up possibly forever until the last continuation frame is parsed.
- As each field is decoded, it's undecoded size is added to the total. Whenever a header block goes over the maximum size, the `frame` will be marked as such.
- Whenever a header block is deemed over max limit, decoding will still continue, but new fields will not be appended to `HeaderMap`. This is also can save wasted hashing.
- To protect against enormous string literals, such that they span multiple continuation frames, a check is made that the combined encoded bytes is less than the max allowed size. While technically not exactly what the spec suggests (counting decoded size instead), this should hopefully only happen when someone is indeed malicious. If found, a `GOAWAY` of `COMPRESSION_ERROR` is sent, and the connection shut down.
- After an oversize header block frame is finished decoding, the streams state machine will notice it is oversize, and handle that.
  - If the local peer is a server, a 431 response is sent, as suggested by the spec.
  - A `REFUSED_STREAM` reset is sent, since we cannot actually give the stream to the user.
- In order to be able to send both the 431 headers frame, and a reset frame afterwards, the scheduled `Canceled` machinery was made more general to a `Scheduled(Reason)` state instead.

Closes #18 
Closes #191
2018-01-05 09:23:48 -08:00
Sean McArthur
3cbc158210 send reset CANCEL when SendStream is dropped with no end-of-stream sent (#210) 2018-01-04 11:06:06 -08:00
Carl Lerche
d0b5b6246a Misc renames (#202)
This patch renames a number of types and functions making
the API more consistent.

* `Server` -> `Connection`
* `Client` -> `SendRequest`
* `Respond` -> `SendResponse`.

It also moves the handshake fns off of `Connection` and make
them free fns in the module. And `Connection::builder` is removed
in favor of `Builder::new`.
2018-01-02 17:02:17 -08:00
Sean McArthur
26e7a2d416 remove erroneous assert when stream has buffered send data (#209) 2018-01-02 12:49:41 -08:00
Kenjiro Nakayama
ecf2e425b4 Add protocol version to response for client (#205) 2018-01-02 12:45:11 -08:00
Kenjiro Nakayama
0c67f7a390 Remove invalid brackets (#203) 2018-01-02 12:25:33 -08:00
Carl Lerche
de4c30a706 Switch unimplemented to assert (#201)
The only caller already guards against the case.

Relates to #192
2017-12-26 12:25:01 -08:00
Carl Lerche
fc75311fae Support writing continuation frames. (#198)
Large header sets might require being split up across multiple frames.
This patch adds support for doing so.
2017-12-20 17:24:29 -08:00
Sean McArthur
a89401dd91 reset pending push promises if user drops all refs (#199) 2017-12-20 16:50:20 -08:00
Sean McArthur
10d8ed7429 Add test that a window update can be received in reserved state (#195) 2017-12-19 20:07:39 -08:00
Carl Lerche
4cc573fa89 Don't panic on poll_trailers called out of order. (#189)
This patch removes a panic in `poll_trailers` that is triggered if
`poll_trailers` is called before `poll_data` returns `None`.

This is done by always trying to notify the receive task when
`poll_data` returns None and there already is pending trailers.
2017-12-19 20:05:12 -08:00
Sean McArthur
1552d62e7c ignore trailers for some time on locally reset streams (#194) 2017-12-19 15:06:05 -08:00
Carl Lerche
4f963588a8 Add more library API documentation (#190)
This includes a section on inbound data control flow.
2017-12-19 12:00:03 -08:00
Sean McArthur
eafd6bfd98 release connection capacity when recv_data has stream error (#186) 2017-12-18 15:08:21 -08:00
Carl Lerche
1a0b1eec2b Start writing API docs (#187)
This focuses mostly on the server module.
2017-12-18 14:27:30 -08:00
Sean McArthur
1ea9a8fc7e ignore received frames on a stream locally reset for some time (#174)
- Adds config duration for how long to ignore frames on a reset stream
- Adds config for how many reset streams can be held at a time
2017-12-18 11:09:38 -08:00
Carl Lerche
a437d46bee Remove most struct level bounds on handshake types (#182) 2017-12-13 22:49:07 -06:00
Carl Lerche
9378846da8 Client should validate request URI. (#181)
This patch adds checks for the request URI and rejects invalid URIs. In
the case of forwarding an HTTP 1.1 request with a path, an "http" pseudo
header is added to satisfy the HTTP/2.0 spec.

Closes #179
2017-12-11 13:42:00 -06:00
Carl Lerche
71888acea5 Additional debug/trace logging (#180) 2017-12-10 13:51:28 -06:00
Sean McArthur
6c68f72fbd notify stream send task when receiving EOF (#178)
* notify stream send task when receiving EOF

* record a conn_error on eof so client can see it

* fix stream id overflow test
2017-12-01 15:58:04 -08:00
Carl Lerche
5d54d8cd79 Fix flow control bug (#177)
This patch fixes a bug that prevents sent data from being flushed to the
socket.

When data is sent, the task managing the connection must be notified. A
guard exists that prevents unnecessary notification of the connection
when the stream does not have any send capacity. However, this guard was
buggy. Instead of notifying the connection if *any* data can be sent, it
notified the connection only when *all* data could be sent.

This patch fixes the check as well as adds some tests that ensure the
connection task is notified.
2017-11-29 12:54:23 -08:00
Luca Bruno
35e0125e82 hpack/decoder: add bound check to peek_u8 (#175)
This updates `peek_u8` in hpack decoder to internally perform bound
checking. This ensures it cannot access bytes out of range once
reaching the end of the buffer.
2017-11-28 21:05:27 -08:00
Sean McArthur
2be2523162 notify stream refs when the connection receives EOF (#176) 2017-11-28 13:42:22 -08:00
Sean McArthur
79003d0d45 reject connection-specific headers (#173)
- When receiving, return a PROTOCOL_ERROR.
- When sending, return a user error about malformed headers.

Closes #36
2017-11-14 11:16:29 -08:00
Eliza Weisman
8a1c4d3d52 Add test and assertion for idle state handling (#160) 2017-10-27 14:14:00 -07:00
Sean McArthur
b1d282799b Add must_use to futures, deny missing docs (#171) 2017-10-27 14:08:16 -07:00
Oliver Gould
2e28f553ba Expose h2::Error::reason (#166) 2017-10-21 13:00:35 -07:00
Eliza Weisman
6a0800d7a4 Clear up unreachable message (#161) 2017-10-21 13:00:15 -07:00
Carl Lerche
c23d11306e Add RecvStream::is_end_stream. (#165)
This function returns true if the `RecvStream` has reached an end of
stream state. This is intended to replace `is_empty` which has confusing
behavior.
2017-10-21 09:59:27 -07:00
Carl Lerche
17453dd307 Loosen some bounds. (#163) 2017-10-20 20:45:09 -07:00