-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 James PIC wrote: > On Fri, Feb 26, 2010 at 4:38 PM, Thomas Nunninger <tho...@nunninger.info> > wrote: >> Hi, >> >> after updating some content in my application, I want to redirect with a 303 >> HTTP response code. If I use ezcMvcExternalRedirect it uses a very unspecific >> 302 code. In HTTP 1.1 you could use 301 and 307 instead of 302. >> >> The German wikipedia (http://de.wikipedia.org/wiki/HTTP-Statuscode) even >> states not to use the 302 redirect when redirecting to other sites because of >> an search engine error (URL hijacking). >> >> Finally I think, I should not patch ezcMvcExternalRedirect but extend it with >> semantic meanings like "content updated, show normal view", "content is >> available on other location" and so on. >> >> But I even need some patch like: >> >> --- response_writers/http.php (Revision 94) >> +++ response_writers/http.php (Arbeitskopie) >> @@ -73,7 +73,14 @@ >> // write output >> foreach ( $this->headers as $header => $value ) >> { >> - header( "$header: $value" ); >> + if ( !is_array( $value ) ) >> + { >> + header( "$header: $value" ); >> + } >> + else >> + { >> + header( "$header: {$value[0]}", true, $value[1] ); >> + } >> } >> // do cookies >> foreach ( $this->response->cookies as $cookie ) >> >> If the value of the header is an array, the second entry is the status code. >> Otherwise, everything behaves like before. >> >> The code seems to be a little bit hackish (because of the semantic in a >> simple >> array struct). But I don't have another idea without breaking BC. >> >> What do you think? > > Wouldn't it be nice to add an $httpCode attribute to ezcMvcResponse > and use it in ezcMvcHttpResponseWriter?
I think thats exactly what the ezcMvcResultStatusObject interface is for. The problem in your implementation is, that you assume that each used reponse writer (aka. protocol) does use the same errorcodes. Lets assume you have a response writer to send a mail. In this case the errorcode would need to be handled in a completely different way. The ezcMvcResultStatusObject does allow just that. Simple implement a status object which signals the special case of redirection you require. For example you could implement a TemporaryRedirectStatusObject. This status object is simply attached to the ezcMvcResponse->status property. The implementation of the status object could look something like that: class TemporaryRedirectStatusObject implements ezcMvcResultStatusObject { public function process( ezcMvcResponseWriter $writer ) { switch( true ) { case $writer instanceof ezcMvcHttpResponseWriter: // Send out the 307 header here break; case $writer instanceof SomeOtherResponseWriter: // Handle other response of this status type here break; // ... } } } This way the status can be handled by different response writers in one place to be a lot more flexible, than confining the handling only to http status codes. HTH. Cheers, Jakob - -- Jakob Westhoff (GPG 0xCBF7FC6A) http://westhoffswelt.de -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iQEcBAEBAgAGBQJLiCJgAAoJEE0XwzzL9/xqa1UIAMN3kpG6QBgRuVNYVra0do9A 5xXpowJELerztYVBIBFFt9AzWV8cgVoXs0LpzKpWfokz9X7BP6MF2WhWHkE/K1+k Wkzxk0+yapGQRgrw/p0qP8HhWo1xNR1s+lkbi3jkdwiyzmK+jeFTcHUdgOgBt1YY MlzVU+mN++LfGyU/0tTEXbUKc+hehhEXy7c+nbTRCxYgCprJunbDiZVZIO8vyNb3 sSSHqbzHfC9VsW+y5YDFdO+WxiTufAZHQdvY3QveOyLXpLmcIvxX6lJ+XjRxyV+h ULensy8YnXztXMLGCdn3ew8iiFUMsbwRgT90qGBfsx0Soa4wrYYoMKK4KGTgPvA= =dJub -----END PGP SIGNATURE----- -- Components mailing list Components@lists.ez.no http://lists.ez.no/mailman/listinfo/components