Skip to content

Commit 3fd9f84

Browse files
author
QuickSander
committed
Introduced lower footprint HttpVersion instead of String based.
1 parent d107d3a commit 3fd9f84

File tree

6 files changed

+108
-11
lines changed

6 files changed

+108
-11
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# ArduinoHttpServer
22

33
[![Build Status](https://travis-ci.org/QuickSander/ArduinoHttpServer.svg?branch=master)](https://travis-ci.org/QuickSander/ArduinoHttpServer)
4+
[![Code Climate](https://codeclimate.com/github/QuickSander/ArduinoHttpServer/badges/gpa.svg)](https://codeclimate.com/github/QuickSander/ArduinoHttpServer)
5+
[![Test Coverage](https://codeclimate.com/github/QuickSander/ArduinoHttpServer/badges/coverage.svg)](https://codeclimate.com/github/QuickSander/ArduinoHttpServer/coverage)
6+
7+
8+
49

510
*Server side minimalistic Object Oriented HTTP protocol implementation for the Arduino platform.*
611

@@ -34,6 +39,11 @@ ArduinoHttpServer::StreamHttpReply httpReply(Serial, "application/json");
3439
httpReply.send("{\"All your base are belong to us!\"}");
3540
```
3641

42+
Documentation
43+
-------------
44+
45+
Documentation available in the [ArduinoHttpServer Github wiki](https://github.com/QuickSander/ArduinoHttpServer/wiki)
46+
3747
Characteristics
3848
---------------
3949
* HTTP parser with protocol validation.

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ArduinoHttpServer",
33
"keywords": "http, get, post, delete, request, reply, protocol, web",
4-
"description": "Server side minimalistic HTTP protocol implementation.",
4+
"description": "Server side minimalistic HTTP protocol implementation that leaves you in control",
55
"authors": {
66
"name": "Sander van Woensel",
77
"url": "http://quicksander.net"

src/internals/HttpVersion.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
//! \file
3+
// ArduinoHttpServer
4+
//
5+
// Created by Sander van Woensel on 20-01-16.
6+
// Copyright (c) 2016 Sander van Woensel. All rights reserved.
7+
//
8+
//! HTTP version
9+
10+
#include "HttpVersion.hpp"
11+
#include "Debug.h"
12+
13+
const char ArduinoHttpServer::HttpVersion::SEPARATOR = '.';
14+
15+
ArduinoHttpServer::HttpVersion::HttpVersion() :
16+
m_major(0),
17+
m_minor(0)
18+
{
19+
}
20+
21+
ArduinoHttpServer::HttpVersion::HttpVersion(const String& version) :
22+
m_major(0),
23+
m_minor(0)
24+
{
25+
int dotIndex(version.lastIndexOf(SEPARATOR));
26+
27+
// Cast might possibly invalidate version data when versions become bigger then 255.
28+
m_major = static_cast<unsigned char>( version.substring(0, dotIndex).toInt() );
29+
m_minor = static_cast<unsigned char>( version.substring(dotIndex+1, version.length()).toInt() );
30+
}
31+
32+
ArduinoHttpServer::HttpVersion& ArduinoHttpServer::HttpVersion::operator=(const HttpVersion& rhs)
33+
{
34+
m_major = rhs.m_major;
35+
m_minor = rhs.m_minor;
36+
37+
return *this;
38+
}
39+
40+
String ArduinoHttpServer::HttpVersion::toString()
41+
{
42+
String version(m_major);
43+
version += SEPARATOR;
44+
version += m_minor;
45+
46+
return version;
47+
}

src/internals/HttpVersion.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
//! \file
3+
// ArduinoHttpServer
4+
//
5+
// Created by Sander van Woensel on 20-01-16.
6+
// Copyright (c) 2016 Sander van Woensel. All rights reserved.
7+
//
8+
//! An HTTP version
9+
10+
#ifndef __ArduinoHttpServer__HttpVersion__
11+
#define __ArduinoHttpServer__HttpVersion__
12+
13+
#include "Arduino.h"
14+
15+
namespace ArduinoHttpServer
16+
{
17+
18+
//! A single HTTP field.
19+
class HttpVersion
20+
{
21+
22+
public:
23+
HttpVersion(const String& version);
24+
HttpVersion();
25+
26+
HttpVersion& operator=(const HttpVersion& rhs);
27+
28+
String toString();
29+
inline unsigned char getMajor() const { return m_major; }
30+
inline unsigned char getMinor() const { return m_minor; }
31+
32+
private:
33+
static const char SEPARATOR;
34+
35+
unsigned char m_major;
36+
unsigned char m_minor;
37+
38+
};
39+
40+
}
41+
42+
#endif

src/internals/StreamHttpReply.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,7 @@ class StreamHttpReply: public AbstractStreamHttpReply
6363
{
6464
public:
6565
StreamHttpReply(Stream& stream, const String& contentType);
66-
6766
virtual void send(const String& data) { AbstractStreamHttpReply::send(data, "OK"); };
68-
69-
70-
protected:
71-
7267
};
7368

7469

src/internals/StreamHttpRequest.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212

1313
#include "HttpResource.hpp"
1414
#include "HttpField.hpp"
15+
#include "HttpVersion.hpp"
1516
#include "Debug.h"
1617

1718
#include <Arduino.h>
1819

1920
namespace ArduinoHttpServer
2021
{
2122

22-
23-
enum MethodEnum {MethodInvalid, MethodGet, MethodPut, MethodPost, MethodHead};
23+
enum MethodEnum
24+
{
25+
MethodInvalid, MethodGet, MethodPut, MethodPost, MethodHead
26+
};
2427

2528

2629
//------------------------------------------------------------------------------
@@ -41,7 +44,7 @@ class StreamHttpRequest
4144
// Header retrieval methods.
4245
inline const ArduinoHttpServer::HttpResource& getResource() const { return m_resource; };
4346
inline const MethodEnum getMethod() const { return m_method; };
44-
inline const String& getVersion() const { return m_version; };
47+
inline const ArduinoHttpServer::HttpVersion& getVersion() const { return m_version; };
4548

4649
// Field retrieval methods.
4750
inline const String& getContentType() const { return m_contentTypeField.getValueAsString(); };
@@ -81,7 +84,7 @@ class StreamHttpRequest
8184
char m_body[MAX_BODY_SIZE];
8285
MethodEnum m_method;
8386
ArduinoHttpServer::HttpResource m_resource;
84-
String m_version;
87+
ArduinoHttpServer::HttpVersion m_version;
8588
ArduinoHttpServer::HttpField m_contentTypeField;
8689
ArduinoHttpServer::HttpField m_contentLengthField;
8790

@@ -248,7 +251,7 @@ void ArduinoHttpServer::StreamHttpRequest<MAX_BODY_LENGTH>::parseVersion()
248251
// String returns unsigned int for length.
249252
if (static_cast<unsigned int>(slashPosition) < version.length() && slashPosition > 0)
250253
{
251-
m_version = version.substring(slashPosition);
254+
m_version = HttpVersion(version.substring(slashPosition));
252255
}
253256
else
254257
{

0 commit comments

Comments
 (0)