WAResponse


Seaside-HTTP

Comment:



Hierarchy:

ProtoObject
Object
WAResponse

Summary:

instance variables:

contentType cookies headers status stream

methods:

instance class
accessing convenience status as yet unclassified

Detail:

instance variables:

contentType
InitialValue:
text/html; charset=utf-8
inferredType:
String
cookies
inferredType:
UndefinedObject
headers
inferredType:
UndefinedObject
status
InitialValue:
200
inferredType:
String
stream
InitialValue:
a RWBinaryOrTextStream ''
inferredType:
RWBinaryOrTextStream

instance methods:

accessing
addCookie: aCookie

	cookies ifNil: [cookies _ OrderedCollection new].
	cookies add: aCookie
contentType

	^ contentType
contentType: mimeTypeString

	contentType _ mimeTypeString
contents

	^ stream reset
contents: aStream

	stream _ aStream
cookieAt: key put: value

	self addCookie: (WACookie key: key value: value)
cookies

	^ cookies ifNil: [#()]
headerAt: key put: value

	headers ifNil: [headers _ Dictionary new].
	headers at: key put: value
headers

	^ headers ifNil: [#()]
initialize

	stream _ SeasidePlatformSupport readWriteStream.
	status _ '200'.
	contentType _ 'text/html; charset=utf-8'.
nextPut: aCharacter

	stream nextPut: aCharacter asCharacter
nextPutAll: aString

	aString do: [:ea | self nextPut: ea]
release

	stream _ cookies _ headers _ nil
status

	^ status
status: statusString

	status _ statusString asString
stream

	^ stream
stream: aStream

	stream _ aStream

convenience
attachmentWithFileName: aString

	self headerAt: 'Content-dispostion' put: 'attachment; filename="', aString, '"'
basicAuthenticationRealm: aString

	self headerAt: 'WWW-Authenticate' put: ('Basic realm="',aString,'"').
	self authenticationFailed
redirectTo: aString

	self headerAt: 'Location' put: aString.
	self redirect.

status
authenticationFailed

	self status: 401
internalError

	self status: 500
notFound

	self status: 404
redirect

	self status: 302

class methods:

as yet unclassified
basicAuthWithRealm: aString

	^ self new basicAuthenticationRealm: aString
document: anObject mimeType: mimeType

	|doc|
	doc _ anObject asMIMEDocument.
	^ self new
		contentType: (mimeType ifNil: [doc contentType]);
		headerAt: 'Expires' put: 'Thu, 01 Jan 2095 12:00:00 GMT';
		nextPutAll: doc content
document: anObject mimeType: mimeString fileName: fileString

	^ (self document: anObject mimeType: mimeString)
		attachmentWithFileName: fileString;
		yourself
internalError: anError

	^ self new
		internalError;
		nextPutAll: '<h1> Internal Error</h1>';
		nextPutAll: '<h2>';
		nextPutAll: anError asString;
		nextPutAll: '</h2>';
		yourself
new

	^ self basicNew initialize
notFound: locationString

	^ self new
		notFound;
		nextPutAll: '<h1> Error: "', locationString, '" not found. </h1>';
		yourself
redirectTo: locationString

	^ self new redirectTo: locationString
refreshWithMessage: aString location: locationString delay: aNumber

	^ self new nextPutAll:
		 ('<html>
			<head>
			<meta http-equiv="refresh" content="',aNumber asString,';URL=',locationString,'">
			<title>',aString,'</title>
			</head>
			<body>
			<h1>',aString,'</h1>
			You are being redirected to <a href="',locationString,'">',locationString,'</a>
			</body>
		</html>');
		yourself
	

^top


- made by Dandelion -