in AZ3166/src/cores/arduino/httpserver/httpd_wsgi.c [274:359]
int httpd_send_response_301(httpd_request_t *req, char *location, const char
*content_type, char *content, int content_len)
{
int ret;
/* Parse the header tags. This is valid only for GET or HEAD request */
if (req->type == HTTPD_REQ_TYPE_GET ||
req->type == HTTPD_REQ_TYPE_HEAD) {
ret = httpd_purge_headers(req->sock);
if (ret != kNoErr) {
httpd_d("Unable to purge headers");
return ret;
}
}
ret = httpd_send(req->sock, HTTP_RES_301, strlen(HTTP_RES_301));
if (ret != kNoErr) {
httpd_d("Error in sending the first line");
return ret;
}
/* Send default headers */
httpd_d("HTTP Req for URI %s", req->wsgi->uri);
if (req->wsgi->hdr_fields) {
ret = httpd_send_default_headers(req->sock,
req->wsgi->hdr_fields);
if (ret != kNoErr) {
httpd_d("Error in sending default headers");
return ret;
}
}
ret = httpd_send_header(req->sock, "Location", location);
if (ret != kNoErr) {
httpd_d("Error in sending Location");
return ret;
}
ret = httpd_send_header(req->sock, "Content-Type", content_type);
if (ret != kNoErr) {
httpd_d("Error in sending Content-Type");
return ret;
}
/* Send Content-Length if non-chunked */
if (!chunked_encoding(req)) {
/* 6 should be more than enough */
char con_len[6];
snprintf(con_len, sizeof(con_len), "%d", content_len);
ret = httpd_send_header(req->sock, "Content-Length", con_len);
if (ret != kNoErr) {
httpd_d("Error in sending Content-Length");
return ret;
}
}
httpd_send_crlf(req->sock);
/* Content can be NULL */
if (!content)
return kNoErr;
/* HTTP Head response does not require any content. It should
* contain identical headers as per the corresponding GET request */
if (req->type != HTTPD_REQ_TYPE_HEAD) {
if (chunked_encoding(req)) {
ret = httpd_send_chunk(req->sock, content, content_len);
if (ret != kNoErr) {
httpd_d("Error in sending response content");
return ret;
}
ret = httpd_send_chunk(req->sock, NULL, 0);
if (ret != kNoErr) {
httpd_d("Error in sending last chunk");
}
} else {
/* Send our data */
ret = httpd_send(req->sock, content, content_len);
if (ret != kNoErr) {
httpd_d("Error sending response");
}
}
}
return ret;
}