mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
stasis-http: Provide a response body for 201 created responses
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@389639 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -166,7 +166,7 @@ void stasis_http_response_no_content(struct stasis_http_response *response);
|
|||||||
* \brief Fill in a <tt>Created</tt> (201) \a stasis_http_response.
|
* \brief Fill in a <tt>Created</tt> (201) \a stasis_http_response.
|
||||||
*/
|
*/
|
||||||
void stasis_http_response_created(struct stasis_http_response *response,
|
void stasis_http_response_created(struct stasis_http_response *response,
|
||||||
const char *url);
|
const char *url, struct ast_json *message);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Fill in \a response with a 500 message for allocation failures.
|
* \brief Fill in \a response with a 500 message for allocation failures.
|
||||||
|
@@ -311,7 +311,7 @@ void stasis_http_response_error(struct stasis_http_response *response,
|
|||||||
void stasis_http_response_ok(struct stasis_http_response *response,
|
void stasis_http_response_ok(struct stasis_http_response *response,
|
||||||
struct ast_json *message)
|
struct ast_json *message)
|
||||||
{
|
{
|
||||||
response->message = message;
|
response->message = ast_json_ref(message);
|
||||||
response->response_code = 200;
|
response->response_code = 200;
|
||||||
response->response_text = "OK";
|
response->response_text = "OK";
|
||||||
}
|
}
|
||||||
@@ -331,9 +331,9 @@ void stasis_http_response_alloc_failed(struct stasis_http_response *response)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stasis_http_response_created(struct stasis_http_response *response,
|
void stasis_http_response_created(struct stasis_http_response *response,
|
||||||
const char *url)
|
const char *url, struct ast_json *message)
|
||||||
{
|
{
|
||||||
response->message = ast_json_null();
|
response->message = ast_json_ref(message);
|
||||||
response->response_code = 201;
|
response->response_code = 201;
|
||||||
response->response_text = "Created";
|
response->response_text = "Created";
|
||||||
ast_str_append(&response->headers, 0, "Location: %s\r\n", url);
|
ast_str_append(&response->headers, 0, "Location: %s\r\n", url);
|
||||||
|
@@ -330,7 +330,6 @@ struct ast_json *stasis_app_playback_to_json(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
json = ast_json_pack("{s: s, s: s, s: s, s: s}",
|
json = ast_json_pack("{s: s, s: s, s: s, s: s}",
|
||||||
"id", playback->id,
|
"id", playback->id,
|
||||||
"media_uri", playback->media,
|
"media_uri", playback->media,
|
||||||
|
@@ -145,6 +145,7 @@ void stasis_http_play_on_channel(struct ast_variable *headers,
|
|||||||
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
|
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
|
||||||
RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
|
RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
|
||||||
RAII_VAR(char *, playback_url, NULL, ast_free);
|
RAII_VAR(char *, playback_url, NULL, ast_free);
|
||||||
|
RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
|
||||||
const char *language;
|
const char *language;
|
||||||
|
|
||||||
ast_assert(response != NULL);
|
ast_assert(response != NULL);
|
||||||
@@ -197,7 +198,15 @@ void stasis_http_play_on_channel(struct ast_variable *headers,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stasis_http_response_created(response, playback_url);
|
json = stasis_app_playback_to_json(playback);
|
||||||
|
if (!json) {
|
||||||
|
stasis_http_response_error(
|
||||||
|
response, 500, "Internal Server Error",
|
||||||
|
"Out of memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stasis_http_response_created(response, playback_url, json);
|
||||||
}
|
}
|
||||||
void stasis_http_record_channel(struct ast_variable *headers, struct ast_record_channel_args *args, struct stasis_http_response *response)
|
void stasis_http_record_channel(struct ast_variable *headers, struct ast_record_channel_args *args, struct stasis_http_response *response)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user