Commit Graph

173 Commits

Author SHA1 Message Date
Nate McMaster c08c57f764 Reject HTTP/1.1 requests that do not have a correct Host header
Improves Kestrel to reject requests that don't conform to HTTP spec.

RFC 7230 section 5.4: "A server MUST respond with a 400 (Bad Request)
status code to any HTTP/1.1 request message that lacks a Host header
 field and to any request message that contains more than one Host
 header field or a Host header field with an invalid field-value."

See https://tools.ietf.org/html/rfc7230#section-5.4.

Other changes:

 - update VS code settings to work better with CLI 2.0
 - update tests that were subject to infinite hangs
2017-04-14 15:48:21 -07:00
Geoff Kizer efa0a48fb1 Add initial Socket transport for Kestrel (#1659)
- This change adds the initial socket transport for Kestrel, all of the tests pass but there are still
a couple of things that aren't done yet.
- The functional tests support running both on both transports but tests aren't running for sockets right now. We need to parameterize these. 
- TimeoutServerTests hard code the libuv transport, this needs to support any transport.
- There is no handling of connection stopping on application shutdown. This is being implemented in kestrel core so transports don't need to handle it. Sockets won't be the default transport until that is the case.
- Performance needs to be looked at, today the SocketTransport doesn't dispatch by default and we're not buffering in kestrel.core, this can hurt as the number of kernel calls map 1:1 with application writes.
2017-04-13 23:10:06 -07:00
John Luo 0723d46ec4 Honor PreferHostingUrls #1575 2017-04-13 18:12:53 -07:00
Nate McMaster ed4a27a827 Remove ListenOptions.Scheme and move IConnectionFilter to .Internal namespace
Add an internal API to ListenOptions to determine if an endpoint is configured to use HTTPS. This is a temporary as the design of connection adapters and configuration will churn before release.
2017-04-13 09:45:26 -07:00
Chris R e043fa871e Make IServer Start and Stop async 2017-04-12 22:23:05 -07:00
Stephen Halter 11ab602b2f Make timeout logic transport agnostic (#1649)
* Make timeout logic transport agnostic

* PR feedback

* More PR feedback
2017-04-12 16:15:46 -07:00
Stephen Halter db159190bd Don't fail tests if port 5000 is in use (#1650) 2017-04-11 23:13:59 -07:00
David Fowler d92c55dbfc Fix spelling nit 2017-04-08 01:50:25 -07:00
Stephen Halter 58284bde5c Don't dispose WriteReqPool and PipeFactory too soon (#1633) 2017-04-08 01:35:02 -07:00
Cesar Blum Silveira f253dbc0c0 Split transport-specific tests and general tests into distinct test projects (#1588).
* Rename EngineTests to LibuvTransportTests.
* Move libuv-specific tests into their own test project.
* Move LibuvOutputConsumerTests.AllocCommitCanBeCalledAfterConnectionClose to new OutputProducerTests class and rename it to WritesNoopAfterConnectionCloses.
* Remove TransportContext from TestServiceContext.
* Make KestrelTests depend on Kestrel.Core only.
* Rename Microsoft.AspNetCore.Server.Kestrel.KestrelTests to Microsoft.AspNetCore.Server.Kestrel.Core.Tests.
* Add Microsoft.AspNetCore.Server.Kestrel.Tests test project for WebHostBuilderKestrelExtensionsTests.
* Increase socket receive timeout in MaxRequestBufferSizeTests to mitigate flakiness.
* Anything using TestServer should be a functional test.
* Move out of LibuvTransportTests tests that are not specific to LibuvTransport.
  - Move to RequestTests:
    - Http11 (rename to Http11KeptAliveByDefault)
    - Http10ContentLength (rename to Http10NotKeptAliveByDefault)
    - Http10KeepAlive
    - Http10KeepAliveNotUsedIfResponseContentLengthNotSet (rename to Http10KeepAliveNotHonoredIfResponseContentLengthNotSet)
    - Http10ContentLengthKeepAlive (rename to Http10KeepAliveHonoredIfResponseContentLengthSet)
    - Expect100ContinueForBody (rename to Expect100ContinueHonored)
    - ZeroContentLengthAssumedOnNonKeepAliveRequestsWithoutContentLengthOrTransferEncodingHeader
    - ConnectionClosesWhenFinReceivedBeforeRequestCompletes (test was actually not marked as Theory, and was incorrect)
    - RequestsCanBeAbortedMidRead
    - RequestHeadersAreResetOnEachRequest
    - UpgradeRequestIsNotKeptAliveOrChunked
    - HeadersAndStreamsAreReused (rename to HeadersAndStreamsAreReusedAcrossRequests)
  - Move to ResponseTests:
    - Http10RequestReceivesHttp11Response (rename to Http11ResponseSentToHttp10Request)
    - ZeroContentLengthSetAutomaticallyAfterNoWrites
    - ZeroContentLengthSetAutomaticallyForNonKeepAliveRequests
    - ZeroContentLengthNotSetAutomaticallyForHeadRequests
    - ZeroContentLengthNotSetAutomaticallyForCertainStatusCodes
    - ConnectionClosedAfter101Response
    - ThrowingResultsIn500Response
    - ThrowingAfterWritingKillsConnection
    - ThrowingAfterPartialWriteKillsConnection
    - ThrowingInOnStartingResultsInFailedWritesAnd500Response
    - ThrowingInOnCompletedIsLoggedAndClosesConnection
    - FailedWritesResultInAbortedRequest
    - NoErrorsLoggedWhenServerEndsConnectionBeforeClient
    - NoResponseSentWhenConnectionIsClosedByServerBeforeClientFinishesSendingRequest
    - ResponseHeadersAreResetOnEachRequest
    - OnStartingCallbacksAreCalledInLastInFirstOutOrder
    - OnCompletedCallbacksAreCalledInLastInFirstOutOrder
  - Remove:
    - RePathEscapeTests (theory data to HttpParsingData)
    - ReDisconnectingClient (what was that testing?)
2017-04-06 19:09:40 -07:00
Mike Harder a594d0eeb8 Workaround for "Explicit RID still required for .NET Framework test projects"
- Addresses #1617
2017-04-06 15:49:23 -07:00
Cesar Blum Silveira 7d50f34b85 Show unexpected error logs in assertion failures. 2017-04-05 11:23:04 -07:00
Cesar Blum Silveira adea477824 Re-write commented out tests in RequestHeaderLimitsTests as Frame tests (#1583). 2017-04-05 10:09:31 -07:00
Cesar Blum Silveira 7ceea5323a Rename namespaces/directories/classes in Kestrel.Core and Transport.Libuv (#1582).
- Put everything in the libuv transport package under `Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.*` namespaces.
- Move stuff in Transport.Libuv/Internal/Http and Transport.Libuv/Internal/Infrastructure to Transport.Libuv/Internal (keep the Networking directory for the libuv wrappers).
- Add `Libuv` prefix to most libuv internal classes.
- Rename `KestrelEngine` to `LibuvTransport`.
- Rename `SocketOutputConsumer` to `LibuvOutputConsumer`.
- Rename `SocketOutputProducer` to `OutputProducer`.
- Fix namespaces in `Microsoft.AspNetCore.Server.Kestrel.Core.`
2017-04-04 13:45:02 -07:00
Nate McMaster 83958886cc
Implement IHttpRequestIdentifierFeature on Frame
This feature generates a unique ID per request. This unique ID can be
used in event source and logging.

Also, this change improves KestrelEventSource by moving it back into the
Kestrel.Core assembly and de-coupling from the Libuv transport. This
adds two new events, RequestStart and RequestStop, which can be used to
identify the correlation between connection ID and request trace
identifier.
2017-03-31 16:54:35 -07:00
Cesar Blum Silveira 6b9d54265f Call ProduceEnd() before consuming request body if response has already started (#1530). 2017-03-31 11:08:55 -07:00
David Fowler b4cec03f65 Update libuv package (#1577)
- The latest libuv package has a new linux RID that should
let us remove the work around with setting the RID
in the docker file and systemd service
2017-03-31 10:19:27 -07:00
David Fowler 1bf9b057d4 Converted test projects to run on netcoreapp2.0
* Converted test projects to run on netcoreapp2.0
* Set DOTNET_RUNTME_ID because of an issue in corehost and RID calculation.
2017-03-31 02:58:18 -07:00
Cesar Blum Silveira 1be31ae2ce Throw if UseUrls specifies HTTPS or path base (#1519). 2017-03-29 20:23:51 -07:00
Nate McMaster 686829d226
Add tests for WritableBuffer extensions and rename WriteAscii => WriteAsciiNoValidation 2017-03-29 16:10:31 -07:00
Stephen Halter 7f785588ef Transport agnostic kestrel refactoring (#1551)
- Add transport interfaces
- Create separate Core and Libuv projects

#828
2017-03-29 16:06:05 -07:00
Pranav K 200d8debc0 Use the SDK version of GetOSPlatform 2017-03-28 14:27:54 -07:00
Cesar Blum Silveira db7348e776 Fix flakiness in WhenAppWritesLessThanContentLengthButRequestIsAbortedErrorNotLogged. 2017-03-27 10:10:28 -07:00
Cesar Blum Silveira 47f1db20e0 Fix races on port acquisition in AddressRegistrationTests (#1520). 2017-03-24 16:46:40 -07:00
Pranav K d6d13a0986 Remove net451 as a cross-compile target 2017-03-24 07:44:11 -07:00
Cesar Blum Silveira 3e6303b6c1 Fix flakiness in connection reset logging tests. 2017-03-23 21:52:29 -07:00
Stephen Halter fffb823e99 Dispose socket in test after synchronous connect 2017-03-22 10:33:38 -07:00
Cesar Blum Silveira 751a0e2e7e Better checks for connection reset in RequestTests.ConnectionReset* tests (#1517) 2017-03-21 19:35:41 -07:00
Cesar Blum Silveira 72587baac3 Check that MaxRequestBufferSize is greater than or equal to MaxRequestHeadersTotalSize (#1491). 2017-03-21 19:25:56 -07:00
Stephen Halter 6c131ea240 Verify scopeids are connectable using Socket before testing Kestrel (#1536) 2017-03-21 18:31:29 -07:00
David Fowler cf576559b6 Fix write after close (#1526)
- Change Alloc to be a Write with a callback that exposes the WritableBuffer.
This allows the ISocketOutput to implementation to not call the callback if
the underlying socket is dead.
- Added a new functional test
2017-03-20 23:58:26 -07:00
Cesar Blum Silveira 3b40ba52ca Check if request is aborted before verifying response bytes written (#1498). 2017-03-20 16:02:25 -07:00
Pavel Krymets 07cbf7faa9 Use pipelines for SocketOutput
- Changed socket output to be based on pipelines
- Changed connection filter glue to be based on pipelines
- Codegen that used `MemoryPoolIterator` for output now uses `WritableBuffer`
- Made `UvWriteReq` async/await friendly with `LibuvAwaitable<T>`
- Deleted MemoryPool and friends
2017-03-18 00:26:00 -07:00
Nate McMaster 9a4a810aa8 Fix race conditions in test event listener 2017-03-15 10:26:09 -07:00
Cesar Blum Silveira 632780dd16 Remove splitting of path and path base (#1050). 2017-03-15 09:57:33 -07:00
Nate McMaster d4c0d4b81e Adds an EventSource named 'Microsoft-AspNetCore-Server-Kestrel' with the following event and properties:
ConnectionStart:
 - connectionId
 - scheme
 - localEndPoint
 - remoteEndPoint

ConnectionStop:
 - connectionId
2017-03-14 16:59:11 -07:00
Nate McMaster 5073d4fdaf Re-add .NET Framework to tests and other cleanup (#1494) 2017-03-14 11:02:49 -07:00
Ben Adams b94912bcb1 InitializeHeaders only at start of parsing/Fix remaining (#1488)
* Don't reinitialize header collection each loop
* Correct remaining tracking value
* Add tests
2017-03-13 15:32:28 -07:00
Cesar Blum Silveira 49f09d5a25 Log rejected request targets. 2017-03-12 18:37:08 -07:00
Nate McMaster 49b328d4c2 Handle absolute, asterisk, and authority-form request targets
Improves compliance with RFC 7230 on the expected handling of requests
that have URI or asterisk in the request target.

This means rejecting asterisk requests that are not OPTIONS and rejecting
authority-form requests taht are not CONNECT.

This also means the server will handle the path and query on targets
with absolute URIs as request-targets.
2017-03-09 16:54:12 -08:00
Cesar Blum Silveira bb973decb8 Unify header rejection messages.
- Log bad headers with escaped non-vchar characters
2017-03-08 15:27:44 -08:00
Cesar Blum Silveira e25eb418bb Change non-printable char representation in log messages from <0xXX> to \xXX. 2017-03-08 10:05:53 -08:00
Cesar Blum Silveira 5743d740b4 Convert HTTP parsing FrameTests to IHttpParser tests (#1416).
- Also fix an issue in KestrelHttpParser where "Header: \r\n" is
  parsed with a value of " " instead of "".
2017-03-07 15:51:11 -08:00
John Luo 06134bc6e0 Add IPv6 loopback address by default #1434 2017-03-06 18:02:28 -08:00
Cesar Blum Silveira 11c7eb5665 Verify all request rejections are logged (#1295). 2017-03-06 12:05:38 -08:00
John Luo 7d94abd606 Enable default server address test 2017-03-06 10:26:32 -08:00
David Fowler 4533383612 React to hosting change
- Kestrel binds to ipv4 by default

Fixes #1432
2017-03-02 23:09:13 -08:00
Stephen Halter 1e0f2b3951 Fix systemd activation tests (#1429) 2017-03-02 17:26:41 -08:00
Cesar Blum Silveira 568aaff9c4 Improve HTTP parsing tests (#1393).
- Add several more test cases
- Share data between functional and unit tests
2017-02-28 14:23:27 -08:00
Cesar Blum Silveira a95743c5f6 Add functional test to verify generated code is up to date (#1369). 2017-02-27 14:19:56 -08:00