Make language more welcoming (#1728)
This commit is contained in:
parent
8ea768b0b8
commit
76b4637122
|
@ -58,7 +58,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* sanity check */
|
/* soundness check */
|
||||||
#if BYTE_ORDER != BIG_ENDIAN
|
#if BYTE_ORDER != BIG_ENDIAN
|
||||||
# if BYTE_ORDER != LITTLE_ENDIAN
|
# if BYTE_ORDER != LITTLE_ENDIAN
|
||||||
# define unsupported 1
|
# define unsupported 1
|
||||||
|
|
|
@ -101,7 +101,7 @@ private enum BodyFraming {
|
||||||
///
|
///
|
||||||
/// Note that for HTTP/1.0 if there is no Content-Length then the response should be followed
|
/// Note that for HTTP/1.0 if there is no Content-Length then the response should be followed
|
||||||
/// by connection close. We require that the user send that connection close: we don't do it.
|
/// by connection close. We require that the user send that connection close: we don't do it.
|
||||||
private func sanitizeTransportHeaders(hasBody: HTTPMethod.HasBody, headers: inout HTTPHeaders, version: HTTPVersion) -> BodyFraming {
|
private func correctlyFrameTransportHeaders(hasBody: HTTPMethod.HasBody, headers: inout HTTPHeaders, version: HTTPVersion) -> BodyFraming {
|
||||||
switch hasBody {
|
switch hasBody {
|
||||||
case .no:
|
case .no:
|
||||||
headers.remove(name: "content-length")
|
headers.remove(name: "content-length")
|
||||||
|
@ -146,8 +146,8 @@ public final class HTTPRequestEncoder: ChannelOutboundHandler, RemovableChannelH
|
||||||
assert(!(request.headers.contains(name: "content-length") &&
|
assert(!(request.headers.contains(name: "content-length") &&
|
||||||
request.headers[canonicalForm: "transfer-encoding"].contains("chunked"[...])),
|
request.headers[canonicalForm: "transfer-encoding"].contains("chunked"[...])),
|
||||||
"illegal HTTP sent: \(request) contains both a content-length and transfer-encoding:chunked")
|
"illegal HTTP sent: \(request) contains both a content-length and transfer-encoding:chunked")
|
||||||
self.isChunked = sanitizeTransportHeaders(hasBody: request.method.hasRequestBody,
|
self.isChunked = correctlyFrameTransportHeaders(hasBody: request.method.hasRequestBody,
|
||||||
headers: &request.headers, version: request.version) == .chunked
|
headers: &request.headers, version: request.version) == .chunked
|
||||||
|
|
||||||
writeHead(wrapOutboundOut: self.wrapOutboundOut, writeStartLine: { buffer in
|
writeHead(wrapOutboundOut: self.wrapOutboundOut, writeStartLine: { buffer in
|
||||||
buffer.write(request: request)
|
buffer.write(request: request)
|
||||||
|
@ -184,8 +184,8 @@ public final class HTTPResponseEncoder: ChannelOutboundHandler, RemovableChannel
|
||||||
assert(!(response.headers.contains(name: "content-length") &&
|
assert(!(response.headers.contains(name: "content-length") &&
|
||||||
response.headers[canonicalForm: "transfer-encoding"].contains("chunked"[...])),
|
response.headers[canonicalForm: "transfer-encoding"].contains("chunked"[...])),
|
||||||
"illegal HTTP sent: \(response) contains both a content-length and transfer-encoding:chunked")
|
"illegal HTTP sent: \(response) contains both a content-length and transfer-encoding:chunked")
|
||||||
self.isChunked = sanitizeTransportHeaders(hasBody: response.status.mayHaveResponseBody ? .yes : .no,
|
self.isChunked = correctlyFrameTransportHeaders(hasBody: response.status.mayHaveResponseBody ? .yes : .no,
|
||||||
headers: &response.headers, version: response.version) == .chunked
|
headers: &response.headers, version: response.version) == .chunked
|
||||||
|
|
||||||
writeHead(wrapOutboundOut: self.wrapOutboundOut, writeStartLine: { buffer in
|
writeHead(wrapOutboundOut: self.wrapOutboundOut, writeStartLine: { buffer in
|
||||||
buffer.write(response: response)
|
buffer.write(response: response)
|
||||||
|
|
|
@ -245,7 +245,7 @@ public final class SNIHandler: ByteToMessageDecoder {
|
||||||
// } body;
|
// } body;
|
||||||
// } Handshake;
|
// } Handshake;
|
||||||
//
|
//
|
||||||
// For the sake of our own sanity, we should check the handshake type and
|
// For the sake of our own happiness, we should check the handshake type and
|
||||||
// validate its length. uint24 is a stupid type, so we have to play some
|
// validate its length. uint24 is a stupid type, so we have to play some
|
||||||
// games here to get this to work. If we check that we have 4 bytes up-front
|
// games here to get this to work. If we check that we have 4 bytes up-front
|
||||||
// we can use unsafe reads: fewer than 4 bytes makes this message bogus.
|
// we can use unsafe reads: fewer than 4 bytes makes this message bogus.
|
||||||
|
|
|
@ -806,7 +806,7 @@ class HTTPClientUpgradeTestCase: XCTestCase {
|
||||||
// Run the processing of the response, but with the upgrade delayed by the client upgrader.
|
// Run the processing of the response, but with the upgrade delayed by the client upgrader.
|
||||||
clientChannel.embeddedEventLoop.run()
|
clientChannel.embeddedEventLoop.run()
|
||||||
|
|
||||||
// Sanity check that the upgrade was delayed.
|
// Soundness check that the upgrade was delayed.
|
||||||
XCTAssertEqual(0, clientUpgrader.upgradedHandler.handlerAddedContextCallCount)
|
XCTAssertEqual(0, clientUpgrader.upgradedHandler.handlerAddedContextCallCount)
|
||||||
|
|
||||||
// Add some non-http data.
|
// Add some non-http data.
|
||||||
|
@ -875,7 +875,7 @@ class HTTPClientUpgradeTestCase: XCTestCase {
|
||||||
let promiseError = errorOnAdditionalChannelWrite as! NIOHTTPClientUpgradeError
|
let promiseError = errorOnAdditionalChannelWrite as! NIOHTTPClientUpgradeError
|
||||||
XCTAssertEqual(NIOHTTPClientUpgradeError.writingToHandlerDuringUpgrade, promiseError)
|
XCTAssertEqual(NIOHTTPClientUpgradeError.writingToHandlerDuringUpgrade, promiseError)
|
||||||
|
|
||||||
// Sanity check that the upgrade was delayed.
|
// Soundness check that the upgrade was delayed.
|
||||||
XCTAssertEqual(0, clientUpgrader.upgradedHandler.handlerAddedContextCallCount)
|
XCTAssertEqual(0, clientUpgrader.upgradedHandler.handlerAddedContextCallCount)
|
||||||
|
|
||||||
// Upgrade now.
|
// Upgrade now.
|
||||||
|
|
|
@ -274,7 +274,7 @@ final class SocketOptionProviderTest: XCTestCase {
|
||||||
let channel = self.clientChannel! as! SocketOptionProvider
|
let channel = self.clientChannel! as! SocketOptionProvider
|
||||||
let tcpInfo = try assertNoThrowWithValue(channel.getTCPInfo().wait())
|
let tcpInfo = try assertNoThrowWithValue(channel.getTCPInfo().wait())
|
||||||
|
|
||||||
// We just need to sanity check something here to ensure that the data is vaguely reasonable.
|
// We just need to soundness check something here to ensure that the data is vaguely reasonable.
|
||||||
XCTAssertEqual(tcpInfo.tcpi_state, UInt8(TCP_ESTABLISHED))
|
XCTAssertEqual(tcpInfo.tcpi_state, UInt8(TCP_ESTABLISHED))
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -286,7 +286,7 @@ final class SocketOptionProviderTest: XCTestCase {
|
||||||
let tcpConnectionInfo = try assertNoThrowWithValue(channel.getTCPConnectionInfo().wait())
|
let tcpConnectionInfo = try assertNoThrowWithValue(channel.getTCPConnectionInfo().wait())
|
||||||
|
|
||||||
#if os(macOS) // deliberately only on macOS
|
#if os(macOS) // deliberately only on macOS
|
||||||
// We just need to sanity check something here to ensure that the data is vaguely reasonable.
|
// We just need to soundness check something here to ensure that the data is vaguely reasonable.
|
||||||
XCTAssertEqual(tcpConnectionInfo.tcpi_state, UInt8(TSI_S_ESTABLISHED))
|
XCTAssertEqual(tcpConnectionInfo.tcpi_state, UInt8(TSI_S_ESTABLISHED))
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,7 +24,11 @@ services:
|
||||||
|
|
||||||
sanity:
|
sanity:
|
||||||
<<: *common
|
<<: *common
|
||||||
command: /bin/bash -xcl "./scripts/sanity.sh"
|
command: /bin/bash -xcl "./scripts/soundness.sh"
|
||||||
|
|
||||||
|
soundness:
|
||||||
|
<<: *common
|
||||||
|
command: /bin/bash -xcl "./scripts/soundness.sh"
|
||||||
|
|
||||||
unit-tests:
|
unit-tests:
|
||||||
<<: *common
|
<<: *common
|
||||||
|
|
|
@ -40,6 +40,9 @@ unacceptable_terms=(
|
||||||
-e blacklis[t]
|
-e blacklis[t]
|
||||||
-e whitelis[t]
|
-e whitelis[t]
|
||||||
-e slav[e]
|
-e slav[e]
|
||||||
|
# this needs to be commented out until we have changed the CI to pick up the
|
||||||
|
# soundness check instead.
|
||||||
|
# -e sanit[y]
|
||||||
)
|
)
|
||||||
if git grep --color=never -i "${unacceptable_terms[@]}" > /dev/null; then
|
if git grep --color=never -i "${unacceptable_terms[@]}" > /dev/null; then
|
||||||
printf "\033[0;31mUnacceptable language found.\033[0m\n"
|
printf "\033[0;31mUnacceptable language found.\033[0m\n"
|
||||||
|
@ -49,7 +52,7 @@ fi
|
||||||
printf "\033[0;32mokay.\033[0m\n"
|
printf "\033[0;32mokay.\033[0m\n"
|
||||||
|
|
||||||
printf "=> Checking license headers... "
|
printf "=> Checking license headers... "
|
||||||
tmp=$(mktemp /tmp/.swift-nio-sanity_XXXXXX)
|
tmp=$(mktemp /tmp/.swift-nio-soundness_XXXXXX)
|
||||||
|
|
||||||
for language in swift-or-c bash dtrace python; do
|
for language in swift-or-c bash dtrace python; do
|
||||||
declare -a matching_files
|
declare -a matching_files
|
Loading…
Reference in New Issue