> > Hi all, > > I tried to create nodes with random names using Sling Post Servlet and > > XHR, but I always receive responses with status code 200 and not 201 > > as expected. > > > Yes, because currently the SlingPostServlet calls the HtmlResponse.send > method with a "setStatus" flag of false, thus the response status is > always set to 200 and the actual status code is in the HTML response. > > > > Also the Location header is missing in the response. > > > This header is only set for a redirect after the post. > > > > Lars > > pointed me to the discussion around this issues in [1]. But I'm > > wondering if there is a consensus on how to solve this? > > > Discussion stopped, actually. > > > > In my eyes > > parsing a XML files to find out what happened is a "no go", because > > this is not standardized in HTTP (which is the interface contract we > > are using here) and it is not funny to deal with this in client side > > JS. On the other hand normal form posts and XHR requests are likely to > > occur more frequently than hidden iframes. > > > Depends on the use case. I tend to agree, that normal XHR should be the > majority. But reality shows that some use cases make heavy use of > > iframes .... > > > So I would suggest to implement the proposal from Felix, which means > > the response always contains the correct response codes and header > > fields (like Location) > > > The Location header seems to in fact not be set for a content creation > request. I agree, that this is a bug in the SlingPostServlet. Could you > please create an issue for that one ? Thanks. the location header is only present for redirects, of course.
> > and there will be another request parameter > > which allows to override the response code for special case handling > > like hidden iframes in forms. This parameter could be named > > sling:post:responseCodeOverride and the value could be the response > > code that should be used. If the parameter is not present the real > > response code will be send. and what do you do if you create and modify and delete several resources at the same time? what response code do you send? > I rather suggest we define a parameter, which will be used as a flag - > for example :ignoreStatus - whether the real response code is expected > (such as 201, 404, etc.) or a 200 response containing the intended > response code. > > And I think the default behaviour (in the absence of this flag) is to > use the real response code and only send a 200 response (for iframe > support) in case of the flag being present and set. i think it's the opposite (see below). that the normal case 1) is the most natural and this could not respond with 201, or something. there are 3 use cases of the post servlet: 1) Normal HTML forms that users fill in content they want to store in the repository. imo, this is mostly the case for normal apps like blogs, wiki, application forms, shopping carts, etc. 2) Special HTML form handling in hidden frames that are used by frameworks that have 'dialogs'. 3) XHR requests for ajax apps the desired responses are quite different though: 1) wants a redirect to the edited or created content after the post. 2) wants a human/machine (browser) readable response. that's why we've chosen an XHTML response that can easily be accessed though the DOM in javascript. 3) wants probably a json response that easily can be transformed into an object structure in javascript. we could include a flag that indicates the desired response: :responseType="xml" :responseType="json" where "xml" is the default and always responds with a 200. where "json" is a json representation of the response and also uses the correct response codes. WDYT ? -- toby
