mirror of
https://github.com/swift-server/async-http-client.git
synced 2026-06-02 07:37:34 +00:00
Redo HTTP cookie parsing (#510)
* Redo HTTP cookie parsing using strptime * Make String(utf8Slice:from:) less ugly * Adjust cookie component parsing to better match RFC-6562
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the AsyncHTTPClient open source project
|
||||
//
|
||||
// Copyright (c) 2018-2021 Apple Inc. and the AsyncHTTPClient project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if __APPLE__
|
||||
#include <xlocale.h>
|
||||
#elif __linux__
|
||||
#define _GNU_SOURCE
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
|
||||
bool swiftahc_cshims_strptime(const char * string, const char * format, struct tm * result) {
|
||||
const char * firstNonProcessed = strptime(string, format, result);
|
||||
if (firstNonProcessed) {
|
||||
return *firstNonProcessed == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool swiftahc_cshims_strptime_l(const char * string, const char * format, struct tm * result, void * locale) {
|
||||
// The pointer cast is fine as long we make sure it really points to a locale_t.
|
||||
const char * firstNonProcessed = strptime_l(string, format, result, (locale_t)locale);
|
||||
if (firstNonProcessed) {
|
||||
return *firstNonProcessed == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user