-
Notifications
You must be signed in to change notification settings - Fork 77
POC implementation of WAComboResponse acting directly on a socket stream #1240
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
base: master
Are you sure you want to change the base?
Changes from all commits
ab5162c
fb28df3
89c6a61
6946a38
dc76211
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| instance creation | ||
| onStream: aStream bufferSize: anInteger codec: aGRCodec | ||
| ^ self basicNew | ||
| initializeOnStream: aStream bufferSize: anInteger codec: aGRCodec; | ||
| yourself |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ destroy | |
|
|
||
| super destroy. | ||
| bufferedStream := nil. | ||
| externalStream := nil | ||
| externalStream := nil. | ||
| codec := nil | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,8 @@ | ||
| public | ||
| flush | ||
| "Flush the receiver and send partial content" | ||
|
|
||
| committed ifFalse: [ self commit ]. | ||
|
|
||
| "Write the partial content if any" | ||
| self nextChunk: bufferedStream count put: bufferedStream contents. | ||
| self nextChunk: bufferedStream size put: bufferedStream contents. | ||
| bufferedStream reset |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| initialization | ||
| initializeOnStream: aStream bufferSize: anInteger codec: aGRCodec | ||
| "Initialize the receiver" | ||
|
|
||
| | rawBufferedStream | | ||
| self initialize. | ||
| codec := aGRCodec. | ||
| rawBufferedStream := GRPlatform current writeCharacterStreamOn: (aGRCodec encodedStringClass new: anInteger). | ||
| bufferedStream := aGRCodec encoderFor: rawBufferedStream. | ||
| externalStream := aStream. | ||
| committed := false. | ||
| closed := false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,19 @@ | ||
| streaming | ||
| nextChunk: anInteger put: data | ||
| "Write a chunk of data to the external stream. Does NOT write if no data is provided since this would logically end the chunked transfer. To end data transfer use #close instead. Raise an error if the response has been committed and closed. | ||
|
|
||
| Unfortunately the size of the chunk is not measured in bytes but characters so we need the ability to pass in the chunk size | ||
| see also | ||
| http://code.google.com/p/seaside/issues/detail?id=733" | ||
| "Write a chunk of data to the external stream. Does NOT write if no data is provided since this would logically end the chunked transfer. To end data transfer use #close instead. Raise an error if the response has been committed and closed." | ||
|
|
||
| data isEmpty ifTrue: [ ^ self ]. | ||
| closed ifTrue: [ self error: 'Response is closed' ]. | ||
|
|
||
| externalStream nextPutAll: (anInteger printStringBase: 16); crlf. | ||
| externalStream nextPutAll: data; crlf; flush | ||
| "Per specification, write the length of the chunk as hexadecimal number. | ||
| See https://httpwg.org/specs/rfc7230.html#chunked.encoding" | ||
| externalStream | ||
| nextPutAll: (anInteger printStringBase: 16) asByteArray; | ||
| "crlf" | ||
| nextPut: 13; | ||
| nextPut: 10; | ||
| nextPutAll: data; | ||
| "crlf" | ||
| nextPut: 13; | ||
| nextPut: 10; | ||
| flush |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| SystemOrganization addCategory: #'Seaside-Core'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Backtracking'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Base'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Cache'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Callbacks'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Configuration'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Exceptions'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Filter'! | ||
| SystemOrganization addCategory: #'Seaside-Core-HTTP'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Libraries'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Manifest'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Rendering'! | ||
| SystemOrganization addCategory: #'Seaside-Core-RequestHandling'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Server'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Utilities'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Backtracking'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Base'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Cache'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Callbacks'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Configuration'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Document'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Exceptions'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Filter'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-HTTP'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Libraries'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Manifest'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Rendering'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-RequestHandling'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Server'! | ||
| SystemOrganization addCategory: #'Seaside-Core-Document-Elements-Seaside-Core-Utilities'! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| accessing | ||
| response | ||
| ^ super response ifNil: [ response := WAComboResponse external: (GRPlatform current writeCharacterStreamOn: (String new: 4096)) ] | ||
| ^ super response ifNil: [ | ||
| response := WAComboResponse | ||
| onStream: (GRPlatform current writeCharacterStreamOn: (ByteArray new: 1024)) | ||
|
Contributor
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. This doesn't look right.
Member
Author
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. It should be something else, yes. I presume, you meant to write We have to be careful though. I remember having to fight a lot with the wrapping streams (i.e., Zinc).
Contributor
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.
Yes
Let's figure out the problem and solve it.
Member
Author
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.
|
||
| bufferSize: 1024 | ||
| codec: (GRCodec forEncoding: 'utf-8') ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| tests | ||
| testCommit | ||
| self response | ||
| contentType: 'text/html'; | ||
| nextPutAll: 'Visit <a href="http://www.seaside.st">seaside.st</a>.'; | ||
| commit. | ||
|
|
||
| self assert: self response isCommitted |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| tests | ||
| testWithBinaryStream | ||
| ByteArray streamContents: [ :stream | | ||
| response := WAComboResponse | ||
| onStream: stream | ||
| bufferSize: 1024 | ||
| codec: (GRCodec forEncoding: 'utf-8'). | ||
|
|
||
| response | ||
| nextPut: Character space; | ||
| flush; | ||
| close ] | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| converting | ||
| responseFor: aZnRequest | ||
| | bufferedStream codecStream | | ||
| bufferedStream := GRPlatform current writeCharacterStreamOn: (self codec encodedStringClass new: 4096). | ||
| codecStream := self codec encoderFor: bufferedStream. | ||
| ^ WAComboResponse | ||
| onBuffered: (GRCountingStream on: codecStream) | ||
| external: aZnRequest stream | ||
| onStream: aZnRequest stream | ||
| bufferSize: 4096 | ||
| codec: self codec |
Uh oh!
There was an error while loading. Please reload this page.