Skip to content

Commit

Permalink
add generating http headers (#218)
Browse files Browse the repository at this point in the history
* add generating http headers

* remove first name with spaces
  • Loading branch information
cieslarmichal authored Nov 7, 2023
1 parent 6c298fc commit 2b93e95
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 17 deletions.
22 changes: 22 additions & 0 deletions include/faker-cxx/Internet.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ class Internet
*/
static unsigned httpStatusCode(std::optional<HttpResponseType> responseType = std::nullopt);

/**
* @brief Generates a random http request header.
*
* @returns Http request header.
*
* @code
* Internet::httpRequestHeader() // "Authorization"
* @endcode
*/
static std::string httpRequestHeader();

/**
* @brief Generates a random http response header.
*
* @returns Http response header.
*
* @code
* Internet::httpResponseHeader() // "Location"
* @endcode
*/
static std::string httpResponseHeader();

/**
* @brief Returns a string containing randomized ipv4 address of the given class.
*
Expand Down
12 changes: 12 additions & 0 deletions src/modules/internet/Internet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "data/DomainSuffixes.h"
#include "data/EmailHosts.h"
#include "data/Emojis.h"
#include "data/HttpRequestHeaders.h"
#include "data/HttpResponseHeaders.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/Person.h"
#include "faker-cxx/String.h"
Expand Down Expand Up @@ -167,6 +169,16 @@ unsigned Internet::httpStatusCode(std::optional<HttpResponseType> responseType)
return Helper::arrayElement<unsigned>(statusCodes);
}

std::string Internet::httpRequestHeader()
{
return Helper::arrayElement<std::string>(httpRequestHeaders);
}

std::string Internet::httpResponseHeader()
{
return Helper::arrayElement<std::string>(httpResponseHeaders);
}

std::string Internet::ipv4(IPv4Class ipv4class)
{
IPv4Address sectors;
Expand Down
18 changes: 18 additions & 0 deletions src/modules/internet/InternetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "data/DomainSuffixes.h"
#include "data/EmailHosts.h"
#include "data/Emojis.h"
#include "data/HttpRequestHeaders.h"
#include "data/HttpResponseHeaders.h"

using namespace ::testing;
using namespace faker;
Expand Down Expand Up @@ -533,6 +535,22 @@ TEST_F(InternetTest, shouldGenerateHttpStatusCode)
{ return generatedHttpStatusCode == statusCode; }));
}

TEST_F(InternetTest, shouldGenerateHttpRequestHeader)
{
const auto generatedHttpRequestHeader = Internet::httpRequestHeader();

ASSERT_TRUE(std::ranges::any_of(httpRequestHeaders, [generatedHttpRequestHeader](const std::string& httpHeader)
{ return generatedHttpRequestHeader == httpHeader; }));
}

TEST_F(InternetTest, shouldGenerateHttpResponseHeader)
{
const auto generatedHttpResponseHeader = Internet::httpResponseHeader();

ASSERT_TRUE(std::ranges::any_of(httpResponseHeaders, [generatedHttpResponseHeader](const std::string& httpHeader)
{ return generatedHttpResponseHeader == httpHeader; }));
}

TEST_F(InternetTest, shouldGenerateHttpInformationalSuccessCode)
{
const auto generatedHttpStatusCode = Internet::httpStatusCode(HttpResponseType::Informational);
Expand Down
7 changes: 1 addition & 6 deletions src/modules/internet/data/EmailHosts.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@

namespace faker
{
const std::vector<std::string> emailHosts = {
"gmail.com",
"yahoo.com",
"hotmail.com",
"outlook.com",
};
const std::vector<std::string> emailHosts = {"gmail.com", "yahoo.com", "hotmail.com", "outlook.com"};

const std::vector<std::string> emailExampleHosts = {"example.org", "example.com", "example.net"};

Expand Down
49 changes: 49 additions & 0 deletions src/modules/internet/data/HttpRequestHeaders.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> httpRequestHeaders = {"A-IM",
"Accept",
"Accept-Charset",
"Accept-Datetime",
"Accept-Encoding",
"Accept-Language",
"Access-Control-Request-Method",
"Access-Control-Request-Headers",
"Authorization",
"Cache-Control",
"Connection",
"Content-Encoding",
"Content-Length",
"Content-MD5",
"Content-Type",
"Cookie",
"Date",
"Expect",
"Forwarded",
"From",
"Host",
"HTTP2-Settings",
"If-Match",
"If-Modified-Since",
"If-None-Match",
"If-Range",
"If-Unmodified-Since",
"Max-Forwards",
"Origin",
"Pragma",
"Prefer",
"Proxy-Authorization",
"Range",
"Referer",
"TE",
"Transfer-Encoding",
"User-Agent",
"Upgrade",
"Upgrade",
"Via",
"Warning"};
}
52 changes: 52 additions & 0 deletions src/modules/internet/data/HttpResponseHeaders.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> httpResponseHeaders = {"Accept-CH",
"Access-Control-Allow-Origin",
"Access-Control-Allow-Credentials",
"Access-Control-Expose-Headers",
"Access-Control-Max-Age",
"Access-Control-Allow-Methods",
"Access-Control-Allow-HeadersAccess-Control-Allow-Origin",
"Accept-Patch",
"Accept-Ranges",
"Age",
"Allow",
"Alt-Svc",
"Cache-Control",
"Connection",
"Content-Disposition",
"Content-Encoding",
"Content-Language",
"Content-Length",
"Content-Location",
"Content-MD5",
"Content-Range",
"Content-Type",
"Date",
"Delta-Base",
"ETag",
"Expires",
"IM",
"Last-Modified",
"Location",
"P3P",
"Pragma",
"Preference-Applied",
"Proxy-Authenticate",
"Public-Key-Pins",
"Retry-After",
"Server",
"Set-Cookie",
"Strict-Transport-Security",
"Transfer-Encoding",
"Tk",
"Upgrade",
"Vary",
"Warning",
"WWW-Authenticate"};
}
22 changes: 11 additions & 11 deletions src/modules/person/data/nepalese/NepaleseFirstNamesMales.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ namespace faker

const std::vector<std::string> nepaleseFirstNamesMales = {

"Sijan", "Prabesh", "Niwang", "Nabin", "Sanjok", "Bibek", "Sujal", "Sagar", "Mukunda", "Arun",
"Nirdesh", "Rabin", "Ramesh", "Manoj", "Bimal", "Anil", "Bipin", "Gopal", "Sunil", "Bikash",
"Sujan", "Sudeep", "Nikhil", "Nishant", "Kiran", "Pramod", "Saroj", "Rajesh", "Dilip", "Sandesh",
"Krishna", "Hari", "Suresh", "Arjun", "Bibash", "Rajiv", "Rajendra", "Bijay", "Aashish", "Raju",
"Sabin", "Keshav", "Rabi", "Sanjeev", "Puspa", "Saroj", "Khem", "Shiva", "Mohan", "Dinesh",
"Rajendra", "Suman", "Ujjwal", "Bhuwan", "Birendra", "Birat", "Lalit", "Bhola", "Pradip", "Nabin",
"Suman", "Shankar", "Laxman", "Sushant", "Roshan", "Buddha", "Kapil", "Rajbir", "Suraj", "Raj Kumar",
"Manish", "Ajay", "Dipak", "Anish", "Sabin", "Prem", "Bijay", "Narayan", "Rajat", "Rishi",
"Yogesh", "Rajendra", "Pawan", "Bhawesh", "Pramod", "Pramod", "Saurav", "Hemant", "Subash", "Sparsha",
"Sabin", "Manohar", "Anuj", "Aryan", "Yogendra", "Nischal", "Samir", "Sanjay", "Bijay", "Rohit",
"Rajat", "Biraj", "Kiran", "Pravin", "Pramod"
"Sijan", "Prabesh", "Niwang", "Nabin", "Sanjok", "Bibek", "Sujal", "Sagar", "Mukunda", "Arun",
"Nirdesh", "Rabin", "Ramesh", "Manoj", "Bimal", "Anil", "Bipin", "Gopal", "Sunil", "Bikash",
"Sujan", "Sudeep", "Nikhil", "Nishant", "Kiran", "Pramod", "Saroj", "Rajesh", "Dilip", "Sandesh",
"Krishna", "Hari", "Suresh", "Arjun", "Bibash", "Rajiv", "Rajendra", "Bijay", "Aashish", "Raju",
"Sabin", "Keshav", "Rabi", "Sanjeev", "Puspa", "Saroj", "Khem", "Shiva", "Mohan", "Dinesh",
"Rajendra", "Suman", "Ujjwal", "Bhuwan", "Birendra", "Birat", "Lalit", "Bhola", "Pradip", "Nabin",
"Suman", "Shankar", "Laxman", "Sushant", "Roshan", "Buddha", "Kapil", "Rajbir", "Suraj", "Manish",
"Ajay", "Dipak", "Anish", "Sabin", "Prem", "Bijay", "Narayan", "Rajat", "Rishi", "Yogesh",
"Rajendra", "Pawan", "Bhawesh", "Pramod", "Pramod", "Saurav", "Hemant", "Subash", "Sparsha", "Sabin",
"Manohar", "Anuj", "Aryan", "Yogendra", "Nischal", "Samir", "Sanjay", "Bijay", "Rohit", "Rajat",
"Biraj", "Kiran", "Pravin", "Pramod"

};

Expand Down

0 comments on commit 2b93e95

Please sign in to comment.