コード例 #1
0
            private static void AddRequestHeaders(HttpHeaders headers, SafeCurlSListHandle handle, bool copyAuthHeaders)
            {
                foreach (KeyValuePair <string, IEnumerable <string> > header in headers)
                {
                    if (string.Equals(header.Key, HttpKnownHeaderNames.ContentLength, StringComparison.OrdinalIgnoreCase) ||
                        (!copyAuthHeaders && string.Equals(header.Key, HttpKnownHeaderNames.Authorization, StringComparison.OrdinalIgnoreCase)))
                    {
                        // avoid overriding libcurl's handling via INFILESIZE/POSTFIELDSIZE
                        continue;
                    }

                    string   headerKeyAndValue;
                    string[] values = header.Value as string[];
                    Debug.Assert(values != null, "Implementation detail, but expected Value to be a string[]");
                    if (values != null && values.Length < 2)
                    {
                        // 0 or 1 values
                        headerKeyAndValue = values.Length == 0 || string.IsNullOrEmpty(values[0]) ?
                                            header.Key + ";" : // semicolon used by libcurl to denote empty value that should be sent
                                            header.Key + ": " + values[0];
                    }
                    else
                    {
                        // Either Values wasn't a string[], or it had 2 or more items. Both are handled by GetHeaderString.
                        string headerValue = headers.GetHeaderString(header.Key);
                        headerKeyAndValue = string.IsNullOrEmpty(headerValue) ?
                                            header.Key + ";" : // semicolon needed by libcurl; see above
                                            header.Key + ": " + headerValue;
                    }

                    ThrowOOMIfFalse(Interop.Http.SListAppend(handle, headerKeyAndValue));
                }
            }
コード例 #2
0
            internal void SetRequestHeaders()
            {
                HttpContentHeaders contentHeaders = null;

                if (_requestMessage.Content != null)
                {
                    SetChunkedModeForSend(_requestMessage);

                    // TODO: Content-Length header isn't getting correctly placed using ToString()
                    // This is a bug in HttpContentHeaders that needs to be fixed.
                    if (_requestMessage.Content.Headers.ContentLength.HasValue)
                    {
                        long contentLength = _requestMessage.Content.Headers.ContentLength.Value;
                        _requestMessage.Content.Headers.ContentLength = null;
                        _requestMessage.Content.Headers.ContentLength = contentLength;
                    }
                    contentHeaders = _requestMessage.Content.Headers;
                }

                var slist = new SafeCurlSListHandle();

                // Add request and content request headers
                if (_requestMessage.Headers != null)
                {
                    AddRequestHeaders(_requestMessage.Headers, slist);
                }
                if (contentHeaders != null)
                {
                    AddRequestHeaders(contentHeaders, slist);
                    if (contentHeaders.ContentType == null)
                    {
                        if (!Interop.Http.SListAppend(slist, NoContentType))
                        {
                            throw CreateHttpRequestException();
                        }
                    }
                }

                // Since libcurl always adds a Transfer-Encoding header, we need to explicitly block
                // it if caller specifically does not want to set the header
                if (_requestMessage.Headers.TransferEncodingChunked.HasValue &&
                    !_requestMessage.Headers.TransferEncodingChunked.Value)
                {
                    if (!Interop.Http.SListAppend(slist, NoTransferEncoding))
                    {
                        throw CreateHttpRequestException();
                    }
                }

                if (!slist.IsInvalid)
                {
                    _requestHeaders = slist;
                    SetCurlOption(CURLoption.CURLOPT_HTTPHEADER, slist);
                    VerboseTrace("Set headers");
                }
                else
                {
                    slist.Dispose();
                }
            }
コード例 #3
0
 private static void AddRequestHeaders(HttpHeaders headers, SafeCurlSListHandle handle)
 {
     foreach (KeyValuePair <string, IEnumerable <string> > header in headers)
     {
         string headerValue       = headers.GetHeaderString(header.Key);
         string headerKeyAndValue = string.IsNullOrEmpty(headerValue) ?
                                    header.Key + ";" : // semicolon used by libcurl to denote empty value that should be sent
                                    header.Key + ": " + headerValue;
         ThrowOOMIfFalse(Interop.Http.SListAppend(handle, headerKeyAndValue));
     }
 }
コード例 #4
0
 private static void AddRequestHeaders(HttpHeaders headers, SafeCurlSListHandle handle)
 {
     foreach (KeyValuePair <string, IEnumerable <string> > header in headers)
     {
         string headerStr = header.Key + ": " + headers.GetHeaderString(header.Key);
         if (!Interop.Http.SListAppend(handle, headerStr))
         {
             throw CreateHttpRequestException();
         }
     }
 }
コード例 #5
0
            internal void SetRequestHeaders()
            {
                var slist = new SafeCurlSListHandle();

                bool suppressContentType;

                if (_requestMessage.Content != null)
                {
                    // Add content request headers
                    AddRequestHeaders(_requestMessage.Content.Headers, slist);
                    suppressContentType = _requestMessage.Content.Headers.ContentType == null;
                }
                else
                {
                    suppressContentType = true;
                }

                if (suppressContentType)
                {
                    // Remove the Content-Type header libcurl adds by default.
                    ThrowOOMIfFalse(Interop.Http.SListAppend(slist, NoContentType));
                }

                // Add request headers
                AddRequestHeaders(_requestMessage.Headers, slist);

                // Since libcurl always adds a Transfer-Encoding header, we need to explicitly block
                // it if caller specifically does not want to set the header
                if (_requestMessage.Headers.TransferEncodingChunked.HasValue &&
                    !_requestMessage.Headers.TransferEncodingChunked.Value)
                {
                    ThrowOOMIfFalse(Interop.Http.SListAppend(slist, NoTransferEncoding));
                }

                // Since libcurl adds an Expect header if it sees enough post data, we need to explicitly block
                // it if caller specifically does not want to set the header
                if (_requestMessage.Headers.ExpectContinue.HasValue &&
                    !_requestMessage.Headers.ExpectContinue.Value)
                {
                    ThrowOOMIfFalse(Interop.Http.SListAppend(slist, NoExpect));
                }

                if (!slist.IsInvalid)
                {
                    SafeCurlSListHandle prevList = _requestHeaders;
                    _requestHeaders = slist;
                    SetCurlOption(CURLoption.CURLOPT_HTTPHEADER, slist);
                    prevList?.Dispose();
                }
                else
                {
                    slist.Dispose();
                }
            }
コード例 #6
0
 private static void AddRequestHeaders(HttpHeaders headers, SafeCurlSListHandle handle)
 {
     foreach (KeyValuePair <string, IEnumerable <string> > header in headers)
     {
         string headerValue       = headers.GetHeaderString(header.Key);
         string headerKeyAndValue = string.IsNullOrEmpty(headerValue) ?
                                    header.Key + ";" : // semicolon used by libcurl to denote empty value that should be sent
                                    header.Key + ": " + headerValue;
         if (!Interop.Http.SListAppend(handle, headerKeyAndValue))
         {
             throw CreateHttpRequestException(new CurlException((int)CURLcode.CURLE_OUT_OF_MEMORY, isMulti: false));
         }
     }
 }
コード例 #7
0
            private static void AddRequestHeaders(HttpHeaders headers, SafeCurlSListHandle handle)
            {
                foreach (KeyValuePair <string, IEnumerable <string> > header in headers)
                {
                    if (string.Equals(header.Key, HttpKnownHeaderNames.ContentLength, StringComparison.OrdinalIgnoreCase))
                    {
                        // avoid overriding libcurl's handling via INFILESIZE/POSTFIELDSIZE
                        continue;
                    }

                    string headerValue       = headers.GetHeaderString(header.Key);
                    string headerKeyAndValue = string.IsNullOrEmpty(headerValue) ?
                                               header.Key + ";" : // semicolon used by libcurl to denote empty value that should be sent
                                               header.Key + ": " + headerValue;
                    ThrowOOMIfFalse(Interop.Http.SListAppend(handle, headerKeyAndValue));
                }
            }
コード例 #8
0
            internal void SetRequestHeaders()
            {
                var slist = new SafeCurlSListHandle();

                // Add content request headers
                if (_requestMessage.Content != null)
                {
                    SetChunkedModeForSend(_requestMessage);

                    _requestMessage.Content.Headers.Remove(HttpKnownHeaderNames.ContentLength); // avoid overriding libcurl's handling via INFILESIZE/POSTFIELDSIZE
                    AddRequestHeaders(_requestMessage.Content.Headers, slist);

                    if (_requestMessage.Content.Headers.ContentType == null)
                    {
                        // Remove the Content-Type header libcurl adds by default.
                        ThrowOOMIfFalse(Interop.Http.SListAppend(slist, NoContentType));
                    }
                }

                // Add request headers
                AddRequestHeaders(_requestMessage.Headers, slist);

                // Since libcurl always adds a Transfer-Encoding header, we need to explicitly block
                // it if caller specifically does not want to set the header
                if (_requestMessage.Headers.TransferEncodingChunked.HasValue &&
                    !_requestMessage.Headers.TransferEncodingChunked.Value)
                {
                    ThrowOOMIfFalse(Interop.Http.SListAppend(slist, NoTransferEncoding));
                }

                if (!slist.IsInvalid)
                {
                    SafeCurlSListHandle prevList = _requestHeaders;
                    _requestHeaders = slist;
                    SetCurlOption(CURLoption.CURLOPT_HTTPHEADER, slist);
                    prevList?.Dispose();
                }
                else
                {
                    slist.Dispose();
                }
            }