HTTP Methods Test Application
Overview
This repository contains two complementary networking applications designed for testing and development purposes:
- HTTP Methods Test Client (main.cpp) - A NetBurner embedded C++ application that tests various HTTP methods against a test server
- HTTP Echo Server (main.go) - A Go-based HTTP server that echoes back request details in both HTML and JSON formats
HTTP Methods Test Client (main.cpp)
Description
The HTTP Methods Test Client is a NetBurner embedded application written in C++ that systematically tests different HTTP methods against a configurable endpoint. The application demonstrates proper usage of NetBurner's HTTP client libraries and JSON handling capabilities.
Features
- Multiple HTTP Method Testing: Tests POST, PUT, GET, HEAD, and DELETE methods
- JSON Request/Response Handling: Sends structured JSON data and parses responses
- HTML Content Retrieval: Can request and display HTML responses
- Device Information: Includes MAC address and uptime in requests
- Automated Testing Loop: Continuously cycles through different HTTP methods
- Network Diagnostics: Optional HTTP debugging output
- Configurable Target: Easy to change target URL for different test servers
HTTP Methods Tested
- POST - Sends JSON message with device info and timestamp
- PUT - Sends JSON message with device info and timestamp
- GET - Requests HTML echo response
- HEAD - Requests headers-only response
- DELETE - Sends DELETE request for testing
Configuration
- Target URL: Currently set to
http://10.2.0.63:20035/
- Request Headers: Configurable Accept headers (application/json or text/html)
- Timeout: 10 seconds per request
- Test Interval: 2 seconds between each method test
JSON Request Format
The application sends JSON requests with the following structure:
{
"DEVICEID": "XX:XX:XX:XX:XX:XX",
"UPTIME": 12345,
"MESSAGE": "At the tone the time will be: 12345"
}
Dependencies
Usage
- Configure the target URL in the source code
- Build and deploy to NetBurner hardware
- Ensure network connectivity
- Application will automatically start testing HTTP methods
- Monitor output via serial console or system diagnostics
HTTP Echo Server (main.go)
Description
The HTTP Echo Server is a Go-based web server designed to echo back HTTP request details. It serves as a perfect companion for testing HTTP clients by providing detailed information about received requests in both human-readable HTML and machine-readable JSON formats.
Features
- Content Negotiation: Returns HTML or JSON based on Accept headers
- Complete Request Echo: Displays method, resource, headers, body, and raw request
- Template-Based Responses: Uses Go templates for flexible output formatting
- Configurable Port: Uses SERVER_PORT environment variable or default port 20035
- Error Handling: Proper HTTP error responses for template or processing errors
Response Formats
HTML Response
Provides a formatted web page showing:
- HTTP Method used
- Resource/URI requested
- All request headers with values
- Request body content
- Complete raw HTTP request dump
JSON Response
Returns structured JSON with:
- Method string
- Resource/URI string
- Headers object with arrays for multi-value headers
- Body content as string
- Complete raw request as string
Configuration
- Default Port: 20035
- Environment Variable: SERVER_PORT overrides default port
- Content Type Detection: Automatically detects JSON requests via Accept header
Running the Server
# Use default port 20035
go run main.go
# Use custom port via environment variable
SERVER_PORT=8080 go run main.go
Template System
The server uses Go's template system with custom functions:
set: Sets a counter value
incr: Increments a counter value
This allows for complex template logic and formatting of response data.
Integration Testing
These two applications work together to provide a complete HTTP testing environment:
- Start the Go echo server on the target network
- Configure the NetBurner client with the server's IP address and port
- Deploy and run the client - it will automatically begin testing
- Monitor responses via the client's serial output and server logs
Network Requirements
- Both applications should be on the same network or have routing between them
- Default port 20035 should be available (or configure alternative)
- NetBurner device needs DHCP or static IP configuration
- Firewall rules should allow HTTP traffic between client and server
Development Notes
NetBurner Client Development
- Uses NetBurner's RTOS and networking stack
- Requires proper initialization and network waiting
- JSON handling through NetBurner's ParsedJsonDataSet class
- HTTP operations through DoJsonHttp and DoHttpEx functions
Go Server Development
- Standard Go HTTP server with template system
- Cross-platform compatibility
- Minimal dependencies (standard library only)
- Easy to extend with additional endpoints or features
Troubleshooting
Common Issues
- Network Connectivity: Ensure both devices can reach each other
- Port Conflicts: Check if port 20035 is available or configure alternative
- Timeout Issues: Adjust timeout values if network is slow
- JSON Parsing Errors: Verify JSON format compatibility
- Template Errors: Check server logs for template parsing issues
Debug Features
- NetBurner client: Enable SetHttpDiag(true) for verbose HTTP debugging
- Go server: Built-in request logging to console
- System diagnostics available on NetBurner platform