Skip to content

Commit

Permalink
Make language more welcoming (apple#1728)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianfett authored Jan 21, 2021
1 parent 8ea768b commit 76b4637
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Sources/CNIOSHA1/c_nio_sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@



/* sanity check */
/* soundness check */
#if BYTE_ORDER != BIG_ENDIAN
# if BYTE_ORDER != LITTLE_ENDIAN
# define unsupported 1
Expand Down
10 changes: 5 additions & 5 deletions Sources/NIOHTTP1/HTTPEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// 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 {
case .no:
headers.remove(name: "content-length")
Expand Down Expand Up @@ -146,8 +146,8 @@ public final class HTTPRequestEncoder: ChannelOutboundHandler, RemovableChannelH
assert(!(request.headers.contains(name: "content-length") &&
request.headers[canonicalForm: "transfer-encoding"].contains("chunked"[...])),
"illegal HTTP sent: \(request) contains both a content-length and transfer-encoding:chunked")
self.isChunked = sanitizeTransportHeaders(hasBody: request.method.hasRequestBody,
headers: &request.headers, version: request.version) == .chunked
self.isChunked = correctlyFrameTransportHeaders(hasBody: request.method.hasRequestBody,
headers: &request.headers, version: request.version) == .chunked

writeHead(wrapOutboundOut: self.wrapOutboundOut, writeStartLine: { buffer in
buffer.write(request: request)
Expand Down Expand Up @@ -184,8 +184,8 @@ public final class HTTPResponseEncoder: ChannelOutboundHandler, RemovableChannel
assert(!(response.headers.contains(name: "content-length") &&
response.headers[canonicalForm: "transfer-encoding"].contains("chunked"[...])),
"illegal HTTP sent: \(response) contains both a content-length and transfer-encoding:chunked")
self.isChunked = sanitizeTransportHeaders(hasBody: response.status.mayHaveResponseBody ? .yes : .no,
headers: &response.headers, version: response.version) == .chunked
self.isChunked = correctlyFrameTransportHeaders(hasBody: response.status.mayHaveResponseBody ? .yes : .no,
headers: &response.headers, version: response.version) == .chunked

writeHead(wrapOutboundOut: self.wrapOutboundOut, writeStartLine: { buffer in
buffer.write(response: response)
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOTLS/SNIHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public final class SNIHandler: ByteToMessageDecoder {
// } body;
// } 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
// 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.
Expand Down
4 changes: 2 additions & 2 deletions Tests/NIOHTTP1Tests/HTTPClientUpgradeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ class HTTPClientUpgradeTestCase: XCTestCase {
// Run the processing of the response, but with the upgrade delayed by the client upgrader.
clientChannel.embeddedEventLoop.run()

// Sanity check that the upgrade was delayed.
// Soundness check that the upgrade was delayed.
XCTAssertEqual(0, clientUpgrader.upgradedHandler.handlerAddedContextCallCount)

// Add some non-http data.
Expand Down Expand Up @@ -875,7 +875,7 @@ class HTTPClientUpgradeTestCase: XCTestCase {
let promiseError = errorOnAdditionalChannelWrite as! NIOHTTPClientUpgradeError
XCTAssertEqual(NIOHTTPClientUpgradeError.writingToHandlerDuringUpgrade, promiseError)

// Sanity check that the upgrade was delayed.
// Soundness check that the upgrade was delayed.
XCTAssertEqual(0, clientUpgrader.upgradedHandler.handlerAddedContextCallCount)

// Upgrade now.
Expand Down
4 changes: 2 additions & 2 deletions Tests/NIOTests/SocketOptionProviderTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ final class SocketOptionProviderTest: XCTestCase {
let channel = self.clientChannel! as! SocketOptionProvider
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))
#endif
}
Expand All @@ -286,7 +286,7 @@ final class SocketOptionProviderTest: XCTestCase {
let tcpConnectionInfo = try assertNoThrowWithValue(channel.getTCPConnectionInfo().wait())

#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))
#endif
#endif
Expand Down
6 changes: 5 additions & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ services:

sanity:
<<: *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:
<<: *common
Expand Down
5 changes: 4 additions & 1 deletion scripts/sanity.sh → scripts/soundness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ unacceptable_terms=(
-e blacklis[t]
-e whitelis[t]
-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
printf "\033[0;31mUnacceptable language found.\033[0m\n"
Expand All @@ -49,7 +52,7 @@ fi
printf "\033[0;32mokay.\033[0m\n"

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
declare -a matching_files
Expand Down

0 comments on commit 76b4637

Please sign in to comment.