-
Notifications
You must be signed in to change notification settings - Fork 125
check body length #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
artemredkin
merged 8 commits into
swift-server:master
from
artemredkin:check_body_length
Jun 16, 2020
Merged
check body length #255
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
be4f9aa
check body length
artemredkin a7c4977
swiftformat and linux tests
artemredkin 3006123
Merge branch 'master' into check_body_length
artemredkin 34ad4a6
review fixes
artemredkin 044765e
swiftformat and linux tests
artemredkin 97a8e96
review fixes
artemredkin 7f31443
Merge branch 'master' into check_body_length
artemredkin 715ab14
fix missing ELG close in test
artemredkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,6 +188,7 @@ internal final class HTTPBin { | |
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
let serverChannel: Channel | ||
let isShutdown: NIOAtomic<Bool> = .makeAtomic(value: false) | ||
var connections: NIOAtomic<Int> | ||
var connectionCount: NIOAtomic<Int> = .makeAtomic(value: 0) | ||
private let activeConnCounterHandler: CountActiveConnectionsHandler | ||
var activeConnections: Int { | ||
|
@@ -233,6 +234,9 @@ internal final class HTTPBin { | |
let activeConnCounterHandler = CountActiveConnectionsHandler() | ||
self.activeConnCounterHandler = activeConnCounterHandler | ||
|
||
let connections = NIOAtomic.makeAtomic(value: 0) | ||
self.connections = connections | ||
|
||
self.serverChannel = try! ServerBootstrap(group: self.group) | ||
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1) | ||
.serverChannelInitializer { channel in | ||
|
@@ -261,10 +265,10 @@ internal final class HTTPBin { | |
}.flatMap { | ||
if ssl { | ||
return HTTPBin.configureTLS(channel: channel).flatMap { | ||
channel.pipeline.addHandler(HttpBinHandler(channelPromise: channelPromise, maxChannelAge: maxChannelAge)) | ||
channel.pipeline.addHandler(HttpBinHandler(channelPromise: channelPromise, maxChannelAge: maxChannelAge, connectionId: connections.add(1))) | ||
} | ||
} else { | ||
return channel.pipeline.addHandler(HttpBinHandler(channelPromise: channelPromise, maxChannelAge: maxChannelAge)) | ||
return channel.pipeline.addHandler(HttpBinHandler(channelPromise: channelPromise, maxChannelAge: maxChannelAge, connectionId: connections.add(1))) | ||
} | ||
} | ||
} | ||
|
@@ -357,8 +361,8 @@ internal struct HTTPResponseBuilder { | |
} | ||
} | ||
|
||
let globalRequestCounter = NIOAtomic<Int>.makeAtomic(value: 0) | ||
let globalConnectionCounter = NIOAtomic<Int>.makeAtomic(value: 0) | ||
//let globalRequestCounter = NIOAtomic<Int>.makeAtomic(value: 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops, fixed, thanks! |
||
//let globalConnectionCounter = NIOAtomic<Int>.makeAtomic(value: 0) | ||
|
||
internal struct RequestInfo: Codable { | ||
var data: String | ||
|
@@ -378,13 +382,13 @@ internal final class HttpBinHandler: ChannelInboundHandler { | |
let maxChannelAge: TimeAmount? | ||
var shouldClose = false | ||
var isServingRequest = false | ||
let myConnectionNumber: Int | ||
var currentRequestNumber: Int = -1 | ||
let connectionId: Int | ||
var requestId: Int = 0 | ||
|
||
init(channelPromise: EventLoopPromise<Channel>? = nil, maxChannelAge: TimeAmount? = nil) { | ||
init(channelPromise: EventLoopPromise<Channel>? = nil, maxChannelAge: TimeAmount? = nil, connectionId: Int) { | ||
self.channelPromise = channelPromise | ||
self.maxChannelAge = maxChannelAge | ||
self.myConnectionNumber = globalConnectionCounter.add(1) | ||
self.connectionId = connectionId | ||
} | ||
|
||
func handlerAdded(context: ChannelHandlerContext) { | ||
|
@@ -424,7 +428,7 @@ internal final class HttpBinHandler: ChannelInboundHandler { | |
switch self.unwrapInboundIn(data) { | ||
case .head(let req): | ||
self.responseHeaders = HTTPHeaders() | ||
self.currentRequestNumber = globalRequestCounter.add(1) | ||
self.requestId += 1 | ||
self.parseAndSetOptions(from: req) | ||
let urlComponents = URLComponents(string: req.uri)! | ||
switch urlComponents.percentEncodedPath { | ||
|
@@ -552,8 +556,15 @@ internal final class HttpBinHandler: ChannelInboundHandler { | |
context.write(wrapOutboundOut(.head(response.head)), promise: nil) | ||
if let body = response.body { | ||
let requestInfo = RequestInfo(data: String(buffer: body), | ||
requestNumber: self.currentRequestNumber, | ||
connectionNumber: self.myConnectionNumber) | ||
requestNumber: self.requestId, | ||
connectionNumber: self.connectionId) | ||
let responseBody = try! JSONEncoder().encodeAsByteBuffer(requestInfo, | ||
allocator: context.channel.allocator) | ||
context.write(wrapOutboundOut(.body(.byteBuffer(responseBody))), promise: nil) | ||
} else { | ||
let requestInfo = RequestInfo(data: "", | ||
requestNumber: self.requestId, | ||
connectionNumber: self.connectionId) | ||
let responseBody = try! JSONEncoder().encodeAsByteBuffer(requestInfo, | ||
allocator: context.channel.allocator) | ||
context.write(wrapOutboundOut(.body(.byteBuffer(responseBody))), promise: nil) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.