Skip to content

Commit

Permalink
Merge pull request #4 from mafredri/header-fix
Browse files Browse the repository at this point in the history
Use CRLF for spec compliant http headers
  • Loading branch information
mafredri authored Jun 11, 2017
2 parents 1b8662d + 7f89203 commit 3cac566
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,20 @@ uint16_t wifi_HttpGet(char *url) {
}
}

const char httpHeaderTpl[] = "HTTP/1.0 %d %s\n"
"Server: OpenBttn\n"
"Access-Control-Allow-Origin: *\n"
"Content-Type: %s\n"
"%s" // "Content-Encoding: %s\n"
"Content-Length: %d\n\n";
const char httpHeaderTpl[] = "HTTP/1.0 %d %s\r\n"
"Server: OpenBttn\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Content-Type: %s\r\n"
"%s" // "Content-Encoding: %s\r\n"
"Content-Length: %d\r\n\r\n";

int wifi_CreateHttpHeader(char *dest, int len, int status,
const char *statusText, const char *contentType,
const char *contentEnc, uint16_t contentLength) {
char contentEncoding[HTTP_HEADER_ENCODING_LENGTH + 1] = {0};
if (contentEnc) {
int s = snprintf(contentEncoding, HTTP_HEADER_ENCODING_LENGTH,
"Content-Encoding: %s\n", contentEnc);
"Content-Encoding: %s\r\n", contentEnc);
if (s < 0) {
return s;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

#define HTTP_HEADER_LENGTH 180
#define HTTP_HEADER_ENCODING_LENGTH \
(18 + 8) // Longest encodings are "compress" and "identity" (8 chars).
(18 + 8 + 2) // Longest encodings are "compress" and "identity" (8 chars).

typedef uint16_t WifiState;

Expand Down

0 comments on commit 3cac566

Please sign in to comment.