formats/http/m_http_simple_writer.c
/* Headers that are specific to a request. */
Headers that are specific to a request.
Headers that are specific to a request .
static M_hash_dict_t *M_http_simple_write_request_headers(const M_hash_dict_t *headers, const char *host, unsigned short port, const char *user_agent)
{
	M_hash_dict_t *myheaders;
	char          *hostport;
	myheaders = M_hash_dict_create(8, 75, M_HASH_DICT_CASECMP|M_HASH_DICT_KEYS_ORDERED|M_HASH_DICT_MULTI_VALUE);
	M_hash_dict_merge(&myheaders, M_hash_dict_duplicate(headers));
	if (!M_str_isempty(host)) {
		M_hash_dict_remove(myheaders, "Host");
		if (port == 0 || port == 80) {
			M_hash_dict_insert(myheaders, "Host", host);
		} else {
			M_asprintf(&hostport, "%s:%u", host, port);
			M_hash_dict_insert(myheaders, "Host", hostport);
			M_free(hostport);
		}
	} else if (!M_hash_dict_get(myheaders, "Host", NULL)) {
		M_hash_dict_destroy(myheaders);
		return NULL;
	}
	if (!M_str_isempty(user_agent))
		M_hash_dict_insert(myheaders, "User-Agent", user_agent);
	return myheaders;
}
static M_hash_dict_t * M_http_simple_write_request_headers ( const M_hash_dict_t * headers , const char * host , unsigned short port , const char * user_agent ) { M_hash_dict_t * myheaders ; char * hostport ; myheaders = M_hash_dict_create ( 8 , 75 , M_HASH_DICT_CASECMP | M_HASH_DICT_KEYS_ORDERED | M_HASH_DICT_MULTI_VALUE ) ; M_hash_dict_merge ( & myheaders , M_hash_dict_duplicate ( headers ) ) ; if ( ! M_str_isempty ( host ) ) { M_hash_dict_remove ( myheaders , " " ) ; if ( port == 0 || port == 80 ) { M_hash_dict_insert ( myheaders , " " , host ) ; } else { M_asprintf ( & hostport , " " , host , port ) ; M_hash_dict_insert ( myheaders , " " , hostport ) ; M_free ( hostport ) ; } } else if ( ! M_hash_dict_get ( myheaders , " " , NULL ) ) { M_hash_dict_destroy ( myheaders ) ; return NULL ; } if ( ! M_str_isempty ( user_agent ) ) M_hash_dict_insert ( myheaders , " " , user_agent ) ; return myheaders ; }
Headers that are specific to a request.
Headers that are specific to a request .
/* Add the host. */ /* Host is required. */ /* Add the user agent. */