MXS-1220: Make the http.hh header public
As it contains utility functions for formatting time_t values to HTTP-date values, there's no real need to make it an internal header.
This commit is contained in:
@ -24,6 +24,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <maxscale/atomic.h>
|
||||
#include <maxscale/debug.h>
|
||||
@ -31,10 +32,9 @@
|
||||
#include <maxscale/utils.h>
|
||||
#include <maxscale/config.h>
|
||||
#include <maxscale/hk_heartbeat.h>
|
||||
#include <sys/stat.h>
|
||||
#include <maxscale/http.hh>
|
||||
|
||||
#include "maxscale/resource.hh"
|
||||
#include "maxscale/http.hh"
|
||||
|
||||
using std::string;
|
||||
using std::ifstream;
|
||||
|
||||
@ -41,6 +41,7 @@
|
||||
#include <maxscale/utils.h>
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/http.hh>
|
||||
|
||||
#include "maxscale/config.h"
|
||||
#include "maxscale/filter.h"
|
||||
|
||||
@ -1,89 +0,0 @@
|
||||
#pragma once
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2019-07-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include <maxscale/cppdefs.hh>
|
||||
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
#include <maxscale/debug.h>
|
||||
|
||||
/**
|
||||
* @brief Return the current HTTP-date
|
||||
*
|
||||
* @return The RFC 1123 compliant date
|
||||
*/
|
||||
static inline std::string http_get_date()
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
struct tm tm;
|
||||
char buf[200]; // Enough to store all dates
|
||||
|
||||
gmtime_r(&now, &tm);
|
||||
strftime(buf, sizeof(buf), "%a, %d %b %y %T GMT", &tm);
|
||||
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert a time_t value into a HTTP-date string
|
||||
*
|
||||
* @param t Time to convert
|
||||
*
|
||||
* @return The time converted to a HTTP-date string
|
||||
*/
|
||||
static inline std::string http_to_date(time_t t)
|
||||
{
|
||||
struct tm tm;
|
||||
char buf[200]; // Enough to store all dates
|
||||
|
||||
gmtime_r(&t, &tm);
|
||||
strftime(buf, sizeof(buf), "%a, %d %b %Y %T GMT", &tm);
|
||||
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert a HTTP-date string into time_t
|
||||
*
|
||||
* @param str HTTP-date formatted string to convert
|
||||
*
|
||||
* @return The time converted to time_t
|
||||
*/
|
||||
static inline time_t http_from_date(const std::string& str)
|
||||
{
|
||||
struct tm tm = {};
|
||||
|
||||
/** First get the GMT time in time_t format */
|
||||
strptime(str.c_str(), "%a, %d %b %Y %T GMT", &tm);
|
||||
time_t t = mktime(&tm);
|
||||
|
||||
/** Then convert it to local time by calculating the difference between
|
||||
* the local time and the GMT time */
|
||||
struct tm local_tm = {};
|
||||
struct tm gmt_tm = {};
|
||||
time_t epoch = 0;
|
||||
|
||||
/** Call tzset() for the sake of portability */
|
||||
tzset();
|
||||
gmtime_r(&epoch, &gmt_tm);
|
||||
localtime_r(&epoch, &local_tm);
|
||||
|
||||
time_t gmt_t = mktime(&gmt_tm);
|
||||
time_t local_t = mktime(&local_tm);
|
||||
|
||||
/** The value of `(gmt_t - local_t)` will be the number of seconds west
|
||||
* from GMT. For timezones east of GMT, it will be negative. */
|
||||
return t - (gmt_t - local_t);
|
||||
}
|
||||
@ -23,8 +23,7 @@
|
||||
|
||||
#include <maxscale/jansson.hh>
|
||||
#include <maxscale/utils.hh>
|
||||
|
||||
#include "http.hh"
|
||||
#include <maxscale/http.hh>
|
||||
|
||||
// The API version part of the URL
|
||||
#define MXS_REST_API_VERSION "v1"
|
||||
|
||||
@ -20,8 +20,7 @@
|
||||
#include <microhttpd.h>
|
||||
|
||||
#include <maxscale/jansson.hh>
|
||||
|
||||
#include "http.hh"
|
||||
#include <maxscale/http.hh>
|
||||
|
||||
/**
|
||||
* A list of default headers that are generated with each response
|
||||
|
||||
@ -20,8 +20,8 @@
|
||||
#include <deque>
|
||||
|
||||
#include <maxscale/server.h>
|
||||
#include <maxscale/http.hh>
|
||||
|
||||
#include "http.hh"
|
||||
#include "httprequest.hh"
|
||||
#include "httpresponse.hh"
|
||||
#include "monitor.h"
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#include <maxscale/spinlock.hh>
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/housekeeper.h>
|
||||
#include <maxscale/http.hh>
|
||||
|
||||
#include "maxscale/httprequest.hh"
|
||||
#include "maxscale/httpresponse.hh"
|
||||
@ -31,7 +32,6 @@
|
||||
#include "maxscale/config_runtime.h"
|
||||
#include "maxscale/modules.h"
|
||||
#include "maxscale/worker.h"
|
||||
#include "maxscale/http.hh"
|
||||
|
||||
using std::list;
|
||||
using std::map;
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <maxscale/debug.h>
|
||||
#include "../maxscale/http.hh"
|
||||
#include <maxscale/http.hh>
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
||||
Reference in New Issue
Block a user