ZnSeasideStaticServerAdaptorDelegate

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ZnSeasideStaticServerAdaptorDelegate

Johan Brichau-2
Hi all, (cc: Sven)

I just started to use the ZnSeasideStaticServerAdaptorDelegate to replace our uses of Seaside-Filesystem (exposing external file directories in Seaside handlers) in the development environment.
The Zinc solution is really better, but I noticed it is a bit too liberal about throwing away error responses coming from the Seaside backend.

Our application (and its API, which is a separate handler) responds different errors which should really be answered to the client.
The ZnSeasideStaticServerAdaptorDelegate tries to look for a file upon _any_ error coming from the Seaside backend and will eventually yield a 404 because it cannot find a file for the given url either.

I propose to change the code as shown below. A file should only be searched when the Seaside backend responds a 404 and if the file was not found, we just return the original error response.
This yields the expected behaviour in our case, which I think is not specific to our application.

What do you think?

Cheers
Johan


handleRequest: znRequest
        "If the Seaside request processing apparatus returns an HTTP response with a 'not found' error
        check the filesystem for a file that matches the uri of the request, if found send the file if not send the original error."

        | response staticResponse |
        response := self adaptor process: znRequest.
        ^ (response isNotFound and: [ response isAuthenticationRequired not ])
                        ifTrue: [
                                staticResponse := self staticDelegate handleRequest: znRequest.
                                staticResponse isNotFound ifTrue:[ response ] ifFalse:[ staticResponse ] ]
                        ifFalse: [ response ]._______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: ZnSeasideStaticServerAdaptorDelegate

Sven Van Caekenberghe-2
Hi Johan,

The original code was a bit of a hack, IMHO, but your solution makes way more sense, because it is more specific, so OK for me.

Sven

> On 22 Sep 2016, at 09:32, Johan Brichau <[hidden email]> wrote:
>
> Hi all, (cc: Sven)
>
> I just started to use the ZnSeasideStaticServerAdaptorDelegate to replace our uses of Seaside-Filesystem (exposing external file directories in Seaside handlers) in the development environment.
> The Zinc solution is really better, but I noticed it is a bit too liberal about throwing away error responses coming from the Seaside backend.
>
> Our application (and its API, which is a separate handler) responds different errors which should really be answered to the client.
> The ZnSeasideStaticServerAdaptorDelegate tries to look for a file upon _any_ error coming from the Seaside backend and will eventually yield a 404 because it cannot find a file for the given url either.
>
> I propose to change the code as shown below. A file should only be searched when the Seaside backend responds a 404 and if the file was not found, we just return the original error response.
> This yields the expected behaviour in our case, which I think is not specific to our application.
>
> What do you think?
>
> Cheers
> Johan
>
>
> handleRequest: znRequest
> "If the Seaside request processing apparatus returns an HTTP response with a 'not found' error
> check the filesystem for a file that matches the uri of the request, if found send the file if not send the original error."
>
> | response staticResponse |
> response := self adaptor process: znRequest.
> ^ (response isNotFound and: [ response isAuthenticationRequired not ])
> ifTrue: [
> staticResponse := self staticDelegate handleRequest: znRequest.
> staticResponse isNotFound ifTrue:[ response ] ifFalse:[ staticResponse ] ]
> ifFalse: [ response ].

_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: ZnSeasideStaticServerAdaptorDelegate

Johan Brichau-2
Hi Sven,

Refined it a little bit more (only try to get a file when it’s a GET request).
Don’t know if there is a more elegant way of doing that but because this adaptor should really only be used in development, it does not matter a lot.

Can you change the package or can we upload it?

thx
Johan

handleRequest: znRequest
        "If the Seaside request processing apparatus returns an HTTP response with a 'not found' error for a GET request,
        check the filesystem for a file that matches the uri of the request, if found send the file if not send the original error."

        | response staticResponse |
        response := self adaptor process: znRequest.
        ^ (response isNotFound and: [ (znRequest method = 'GET') and: [ response isAuthenticationRequired not ] ])
                        ifTrue: [
                                staticResponse := self staticDelegate handleRequest: znRequest.
                                staticResponse isNotFound ifTrue:[ response ] ifFalse:[ staticResponse ] ]
                        ifFalse: [ response ].

> On 22 Sep 2016, at 09:38, Sven Van Caekenberghe <[hidden email]> wrote:
>
> Hi Johan,
>
> The original code was a bit of a hack, IMHO, but your solution makes way more sense, because it is more specific, so OK for me.
>
> Sven
>
>> On 22 Sep 2016, at 09:32, Johan Brichau <[hidden email]> wrote:
>>
>> Hi all, (cc: Sven)
>>
>> I just started to use the ZnSeasideStaticServerAdaptorDelegate to replace our uses of Seaside-Filesystem (exposing external file directories in Seaside handlers) in the development environment.
>> The Zinc solution is really better, but I noticed it is a bit too liberal about throwing away error responses coming from the Seaside backend.
>>
>> Our application (and its API, which is a separate handler) responds different errors which should really be answered to the client.
>> The ZnSeasideStaticServerAdaptorDelegate tries to look for a file upon _any_ error coming from the Seaside backend and will eventually yield a 404 because it cannot find a file for the given url either.
>>
>> I propose to change the code as shown below. A file should only be searched when the Seaside backend responds a 404 and if the file was not found, we just return the original error response.
>> This yields the expected behaviour in our case, which I think is not specific to our application.
>>
>> What do you think?
>>
>> Cheers
>> Johan
>>
>>
>> handleRequest: znRequest
>> "If the Seaside request processing apparatus returns an HTTP response with a 'not found' error
>> check the filesystem for a file that matches the uri of the request, if found send the file if not send the original error."
>>
>> | response staticResponse |
>> response := self adaptor process: znRequest.
>> ^ (response isNotFound and: [ response isAuthenticationRequired not ])
>> ifTrue: [
>> staticResponse := self staticDelegate handleRequest: znRequest.
>> staticResponse isNotFound ifTrue:[ response ] ifFalse:[ staticResponse ] ]
>> ifFalse: [ response ].
>

_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev
Reply | Threaded
Open this post in threaded view
|

Re: ZnSeasideStaticServerAdaptorDelegate

Sven Van Caekenberghe-2

> On 22 Sep 2016, at 10:06, Johan Brichau <[hidden email]> wrote:
>
> Hi Sven,
>
> Refined it a little bit more (only try to get a file when it’s a GET request).
> Don’t know if there is a more elegant way of doing that but because this adaptor should really only be used in development, it does not matter a lot.
>
> Can you change the package or can we upload it?

Done:

===
Name: Zinc-Seaside-SvenVanCaekenberghe.46
Author: SvenVanCaekenberghe
Time: 26 September 2016, 11:14:44.435222 pm
UUID: ef50a73e-9858-4600-bc4a-1099317b3068
Ancestors: Zinc-Seaside-pmm.45

Change ZnSeasideStaticServerAdaptorDelegate>>#handleRequest: to be a bit more conservative: only if Seaside returns a 404 Not Found for an unauthenticated GET request, try a static file access, else return **the original** error response [ thanks Johan Brichau for this fix ]
===

Sven

>
> thx
> Johan
>
> handleRequest: znRequest
> "If the Seaside request processing apparatus returns an HTTP response with a 'not found' error for a GET request,
> check the filesystem for a file that matches the uri of the request, if found send the file if not send the original error."
>
> | response staticResponse |
> response := self adaptor process: znRequest.
> ^ (response isNotFound and: [ (znRequest method = 'GET') and: [ response isAuthenticationRequired not ] ])
> ifTrue: [
> staticResponse := self staticDelegate handleRequest: znRequest.
> staticResponse isNotFound ifTrue:[ response ] ifFalse:[ staticResponse ] ]
> ifFalse: [ response ].
>
>> On 22 Sep 2016, at 09:38, Sven Van Caekenberghe <[hidden email]> wrote:
>>
>> Hi Johan,
>>
>> The original code was a bit of a hack, IMHO, but your solution makes way more sense, because it is more specific, so OK for me.
>>
>> Sven
>>
>>> On 22 Sep 2016, at 09:32, Johan Brichau <[hidden email]> wrote:
>>>
>>> Hi all, (cc: Sven)
>>>
>>> I just started to use the ZnSeasideStaticServerAdaptorDelegate to replace our uses of Seaside-Filesystem (exposing external file directories in Seaside handlers) in the development environment.
>>> The Zinc solution is really better, but I noticed it is a bit too liberal about throwing away error responses coming from the Seaside backend.
>>>
>>> Our application (and its API, which is a separate handler) responds different errors which should really be answered to the client.
>>> The ZnSeasideStaticServerAdaptorDelegate tries to look for a file upon _any_ error coming from the Seaside backend and will eventually yield a 404 because it cannot find a file for the given url either.
>>>
>>> I propose to change the code as shown below. A file should only be searched when the Seaside backend responds a 404 and if the file was not found, we just return the original error response.
>>> This yields the expected behaviour in our case, which I think is not specific to our application.
>>>
>>> What do you think?
>>>
>>> Cheers
>>> Johan
>>>
>>>
>>> handleRequest: znRequest
>>> "If the Seaside request processing apparatus returns an HTTP response with a 'not found' error
>>> check the filesystem for a file that matches the uri of the request, if found send the file if not send the original error."
>>>
>>> | response staticResponse |
>>> response := self adaptor process: znRequest.
>>> ^ (response isNotFound and: [ response isAuthenticationRequired not ])
>>> ifTrue: [
>>> staticResponse := self staticDelegate handleRequest: znRequest.
>>> staticResponse isNotFound ifTrue:[ response ] ifFalse:[ staticResponse ] ]
>>> ifFalse: [ response ].
>>
>

_______________________________________________
seaside-dev mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/seaside-dev