Skip to content

Commit

Permalink
Issue GsDevKit#58: conversion of ZnServerTests to support ZnGsServerT…
Browse files Browse the repository at this point in the history
…ests ... support full range of ZnServer options in ZnGemServer
  • Loading branch information
dalehenrich committed Dec 14, 2014
1 parent 5cf3b2d commit 6aac715
Show file tree
Hide file tree
Showing 158 changed files with 673 additions and 230 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
accessing
authenticator: anObject
options
authenticator: object
"Set the object that will be sent #authenticateRequest:do:
to authenticate or refuse the requests. Can be nil.
When authentication succeeds, the block should be executed,
when authentication fails, a appropriate response should be returned"

authenticator := anObject
self optionAt: #authenticator put: object
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
accessing
options
authenticator

^authenticator
"Return the optional authenticator,
the object that will be sent #authenticateRequest:do:
to authenticate or refuse the requests.
When authentication succeeds, the block should be executed,
when authentication fails, a appropriate response should be returned.
If there is no authenticator, all requests will pass"

^ self optionAt: #authenticator ifAbsent: [ nil ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
options
bindingAddress: address
"Set the interface address we will be listening on.
Specify nil to listen on all/any interfaces, the default.
Address must be a 4 element ByteArray, like #[127 0 0 1].
Cannot be changed after the server is already running."

self optionAt: #bindAddress put: address
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
options
bindingAddress
"Return the interface address we are (or will be) listening on.
Nil means that we are (or will be) listening on all/any interfaces."

^ self optionAt: #bindAddress ifAbsent: [ nil ]
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
accessing
debugMode: anObject

debugMode := anObject
options
debugMode: boolean
"Set my debug mode, the default being false.
In debug mode, Smalltalk Error during #handleRequest: will raise a Debugger.
When not in debug mode, a Smalltalk Error during #handleRequest: will result in an HTTP Server Error response."

^ self optionAt: #debugMode put: boolean
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
accessing
options
debugMode
debugMode ifNil: [ debugMode := false ].
^ debugMode
"Return whether we are in debug mode, the default is false."

^ self optionAt: #debugMode ifAbsent: [ false ]
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
initialization
delegate: aZnDelegate
^ delegate := aZnDelegate
options
delegate: object
"Set the delegate to object. Can be nil.
This will be sent #handleRequest: to handle a request and produce a response"

self optionAt: #delegate put: object
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
accessing
options
delegate
^ delegate
"Return the optional delegate,
the object that will be sent #handleRequest: to handle a request and produce a response.
The default delegate is ZnDefaultServerDelegate"

^ self optionAt: #delegate ifAbsentPut: [ ZnDefaultServerDelegate new ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
options
maximumEntitySize: integer
"Set the maximum entity size in bytes that I will read from a stream before signalling ZnEntityTooLarge"

^ self optionAt: #maximumEntitySize put: integer
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
options
maximumEntitySize
"Return the maximum entity size in bytes that I will read from a stream before signalling ZnEntityTooLarge"

^ self optionAt: #maximumEntitySize ifAbsent: [ ZnConstants defaultMaximumEntitySize ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
accessing
optionAt: key ifAbsent: block
"Return my option/settings stored under key.
Execute block if I have no such option/setting.
This is a generic interface, see my options protocol for specific usages."

options ifNil: [ ^ block value ].
^ options at: key ifAbsent: block
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
accessing
optionAt: key ifAbsentPut: block
"Return my option/settings stored under key.
If I have no such option/setting, store the result of evaluating block as new value and return it.
This is a generic interface, see my options protocol for specific usages."

^ options at: key ifAbsentPut: block
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
accessing
optionAt: key put: value
"Set my option/setting identified by key to be value.
This is a generic interface, see my options protocol for specific usages."

options ifNil: [ options := Dictionary new ].
options at: key put: value
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
options
reader: block
"Customize how entities are read from a stream, see #reader"

self optionAt: #reader put: block
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
options
reader
"Return a block that when given a stream reads an entity from it."

^ self optionAt: #reader ifAbsentPut: [ [ :stream | ZnRequest readFrom: stream ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
options
route: object
"Set the route of the server.
This is a short identification string to be appended at the end of server session ids, separated by a dot.
Routes are used by load balancers and proxies to correctly implement session affiinity or stickyness.
The default is nil, meaning that no route has to be appended."

self optionAt: #route put: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
options
route
"Return the route of the server.
This is a short identification string to be appended at the end of server session ids, separated by a dot.
Routes are used by load balancers and proxies to correctly implement session affiinity or stickyness.
The default is nil, meaning that no route has to be appended."

^ self optionAt: #route ifAbsent: [ nil ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
options
serverUrl: urlObject
"Set the explicit external server URL to urlObject. Defaults to nil.
urlObject should be a ZnUrl or a String that parses correctly to one.
See also #url."

^ self optionAt: #serverUrl put: urlObject asZnUrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
options
serverUrl
"Return the explicitely set external server URL, if any. Defaults to nil."

^ self optionAt: #serverUrl ifAbsent: [ nil ]
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ startBasicServerOn: port

| server startMessage |
server := (self serverClass on: port)
delegate: self delegate;
debugMode: self debugMode;
log: self log;
_options: options;
yourself.
self authenticator ifNotNil: [ :auth | server authenticator: auth ].
startMessage := server printString , ' (native thread: '
, self activeProcessIsNative printString , ')'.
Transcript
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
options
useGzipCompressionAndChunking: boolean
"Set whether we should try to use gzip content encoding and chunked transfer encoding, the default being false."

self optionAt: #useGzipCompressionAndChunking put: boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
options
useGzipCompressionAndChunking
"Return whether we should try to use gzip content encoding and chunked transfer encoding, the default is false."

^ self optionAt: #useGzipCompressionAndChunking ifAbsent: [ false ]
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"class" : {
"serverClass" : "dkh 11/29/2014 06:40" },
"instance" : {
"authenticator" : "dkh 12/13/2014 19:21",
"authenticator:" : "dkh 12/13/2014 19:21",
"authenticator" : "dkh 12/14/2014 07:35",
"authenticator:" : "dkh 12/14/2014 07:35",
"bindingAddress" : "dkh 12/14/2014 07:35",
"bindingAddress:" : "dkh 12/14/2014 07:35",
"breakpointExceptionSet" : "dkh 12/05/2014 15:03",
"breakpointExceptionSet:" : "dkh 12/05/2014 15:03",
"debugMode" : "dkh 11/30/2014 21:29",
"debugMode:" : "dkh 11/29/2014 08:44",
"delegate" : "dkh 11/29/2014 08:44",
"delegate:" : "dkh 11/29/2014 08:44",
"debugMode" : "dkh 12/14/2014 07:35",
"debugMode:" : "dkh 12/14/2014 07:35",
"delegate" : "dkh 12/14/2014 07:35",
"delegate:" : "dkh 12/14/2014 07:36",
"enableContinuations" : "dkh 12/03/2014 12:21",
"enableContinuations:" : "dkh 12/04/2014 09:56",
"initialize" : "dkh 12/10/2014 14:49",
Expand All @@ -26,6 +28,19 @@
"logListener:" : "dkh 12/04/2014 09:56",
"logToObjectLog" : "dkh 12/03/2014 12:23",
"logToTranscript" : "dkh 12/03/2014 12:16",
"maximumEntitySize" : "dkh 12/14/2014 07:36",
"maximumEntitySize:" : "dkh 12/14/2014 07:36",
"optionAt:ifAbsent:" : "dkh 12/14/2014 07:34",
"optionAt:ifAbsentPut:" : "dkh 12/14/2014 07:34",
"optionAt:put:" : "dkh 12/14/2014 07:33",
"reader" : "dkh 12/14/2014 07:36",
"reader:" : "dkh 12/14/2014 07:36",
"route" : "dkh 12/14/2014 07:36",
"route:" : "dkh 12/14/2014 07:36",
"scheme" : "dkh 12/13/2014 19:24",
"startBasicServerOn:" : "dkh 12/13/2014 19:22",
"stop" : "dkh 12/13/2014 19:43" } }
"serverUrl" : "dkh 12/14/2014 07:36",
"serverUrl:" : "dkh 12/14/2014 07:37",
"startBasicServerOn:" : "dkh 12/14/2014 07:40",
"stop" : "dkh 12/13/2014 19:43",
"useGzipCompressionAndChunking" : "dkh 12/14/2014 07:37",
"useGzipCompressionAndChunking:" : "dkh 12/14/2014 07:37" } }
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
],
"commentStamp" : "",
"instvars" : [
"delegate",
"debugMode",
"enableContinuations",
"log",
"logListener",
"logFilter",
"breakpointExceptionSet",
"authenticator" ],
"options" ],
"name" : "ZnGemServer",
"pools" : [
],
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ printHMSOn: aStream
nextPut: $:;
nextPutAll: (self minute asString padded: #left to: 2 with: $0);
nextPut: $:;
nextPutAll: (self second asString padded: #left to: 2 with: $0).
nextPutAll: (self second asString padded: #left to: 2 with: $0).
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ printYMDOn: aStream
"Print just YYYY-MM-DD part.
If the year is negative, prints out '-YYYY-MM-DD'."

^self printYMDOn: aStream withLeadingSpace: false.
^self printYMDOn: aStream withLeadingSpace: false.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ printYMDOn: aStream withLeadingSpace: printLeadingSpaceToo
nextPut: $-;
nextPutAll: (month asString padded: #left to: 2 with: $0);
nextPut: $-;
nextPutAll: (day asString padded: #left to: 2 with: $0)
nextPutAll: (day asString padded: #left to: 2 with: $0)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ updating
amount: newValue

"Modify the value of the instance variable 'amount'."
amount := newValue
amount := newValue
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ accessing
amount

"Return the value of the instance variable 'amount'."
^amount
^amount
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ updating
total: newValue

"Modify the value of the instance variable 'total'."
total := newValue
total := newValue
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ accessing
total

"Return the value of the instance variable 'total'."
^total
^total
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ print: positiveNumberString on: aStream prefix: prefix length: minimum padded: z
ifTrue: [aStream nextPutAll: prefix; nextPutAll: (String new: padLength withAll: $0)]
ifFalse: [aStream nextPutAll: (String new: padLength withAll: Character space); nextPutAll: prefix]]
ifFalse: [aStream nextPutAll: prefix].
aStream nextPutAll: positiveNumberString
aStream nextPutAll: positiveNumberString

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
printOn: aStream base: base length: minimum padded: zeroFlag
| prefix |
prefix := self negative ifTrue: ['-'] ifFalse: [String new].
self print: (self abs printStringBase: base) on: aStream prefix: prefix length: minimum padded: zeroFlag
self print: (self abs printStringBase: base) on: aStream prefix: prefix length: minimum padded: zeroFlag
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ updating
object: newValue

"Modify the value of the instance variable 'object'."
object := newValue
object := newValue
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ accessing
object

"Return the value of the instance variable 'object'."
^object
^object
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ isRequestAuthenticated: request
authorization := [ request basicAuthentication ] on: Error do: [:err | ^ false ].
username := authorization first.
password := authorization second.
^ (credentials at: username ifAbsent: [ nil ]) = password
^ (credentials at: username ifAbsent: [ nil ]) = password

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
accessing
collectionSpecies
^ self isBinary ifTrue: [ ByteArray ] ifFalse: [ String ]
^ self isBinary ifTrue: [ ByteArray ] ifFalse: [ String ]

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
private
ensureChunkBufferOfSize: size
(chunk notNil and: [ size <= chunk size ]) ifTrue: [ ^ self ].
chunk := self collectionSpecies new: size.
chunk := self collectionSpecies new: size.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ ensureChunkOrAtEnd
atEnd
ifTrue: [ ^ self ].
(chunk isNil or: [ position >= limit ])
ifTrue: [ self getNextChunk ]
ifTrue: [ self getNextChunk ]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
testing
isBinary
^ stream isBinary
^ stream isBinary
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
testing
isBinary
^ stream isBinary
^ stream isBinary

0 comments on commit 6aac715

Please sign in to comment.